In this example I will show how to create a very simple catalog display. I will use the music database from example 5. This example uses information from all the previous examples.
The query page (source: example-10a.php) is simply a form with a drop-down selection list of all available musical genres. This is used to submit data to the result page. In previous examples, I used php variables and the post method. In this example I use the submit method. This uses the variables as part of the URL. (See example 9.) Because the data is passed as part of the URL, the query can be linked to directly. This is what the blues link at the bottom of the query page does. This allows users to bookmark searches.
The options in the selection list are generated using a query to the genre table in my database. The option value is the key in the genre table. This isn't very useful for users, so the visible value is the name of the genre.
The result page (source: example-10b.php) first opens a database connection. It then creates a SQL query based on the value of the genre variable passed. The results of the query are parsed and echoed to the html. I added some simple error checking to this page. If $genre is undefined or not a number, the entire music table is displayed. This is demonstrated by the view all link. If a genre is input, but is not valid, an error message appears.
For this example, I added a field for an image name to the music table. It may be better to generate the image name from other fields. I could have named the images by the id field in the music table. I could have combined the artist name and album name to create the image name. It is also possible to have the image inside the database as a BLOB field. Choose whatever method works best for your project.