Querying the Database

Next, the code returns to the familiar territory of previous example where, in the following four lines of code, a query is sent to MySQL asking to see all the records in the classics table. After that, $rows is set to a value representing the number of rows in the table and a for loop is entered to display the contents of each row.
I have altered the next bit of code to simplify things. Instead of using the <br> tags for line feeds , I have chosen to use a <pre> tag to line up the display of each record in a pleasing manner.
After the display of each record there is a second form that also posts to sqltest.php (the program itself) but this time contains two hidden fields: delete and isbn. The delete field is set to “yes” and isbn to the value held in $row[4], which contains the ISBN for the record. Then a Submit button with the name DELETE RECORD is displayed and the form is closed. A curly brace then completes the for loop, which will continue until all records have been displayed.
Finally, you see the definition for the function get_post, which we’ve already looked at. And that’s it—our first PHP program to manipulate a MySQL database. So, let’s check out what it can do.


You may also like...