Selecting records
So, when you have your database finally designed and data is inserted into appropriate files, you probably want to select some titles and display them. Fine! But before you can do it, you must connect to your database:
Now $novels contains array with all data.
All right then, let's display all novels, in which the principal character is incomparable detective Hercule Poirot! Here we go:
BTW, although you could write the above line this way:
and in fact it would give exactly the same result, however it would also contradict a good rule of programming. What if you later change name from Hercule Poirot to Hercules Poirot? You will have to change your code instead of data. Bad, bad idea.
One record from $hercule looks like this (to display it, I used print_r() PHP function):
[8] => Array ( [id] => 11 [title] => Hercule Poirot's Christmas [%aka] => 3,4 [aka] => Array { [0] => A Holiday for Murder [1] => Murder for Christmas } [@protagonist] => 1 [year] => 1938 [protagonist] => Hercule Poirot )
You should write a template to display the data, so it looks for instance like in example below:
All right, that's it for this step. Just one more ptb_select example, so you see how powerful it is:
This line will:
- select all the novels in which Hercules Poirot is the principal character AND which were published after 1930
- sort them alphabetically, according to their title
Finally, to find all records, where Poirot's surname is a part of the main title, you'd need: