PHP Recordsets

I got most of the information from the desciption of mysql_reult function. I also found the information from the book on this general topic to be most insightful. I have worked with recordsets before, but this has been a good to help me really understand what there are and how they work.

Querying the Database

First of all, to even think about a recordset there has to be a connection to a database and a relevant query. In the query the appropriate information is asked for from a specific table. An example: "SELECT name, date, message FROM contact". This query would return the name, date, and message from each row in the contact table. The information returned will be in the form of a recordset, also know as a resultset. The formstion of the select statement will deturmine the result set that you get back.

Working with the Recordset

Once the recordset is returned from the query it is not in a form that can be directly used. Using the built in while loop, the code will step through the recordset row by row. An example:

$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))

In this way we will be able work with the requested information. One thing to keep in mind is the amount of information in the recordset. If too much information is returned it might not be useful to us or the user. This might make it necessary to display the results in groups on different pages.

Working Example / References

This is a hard one to show a working example of on the web. Any system that uses MySQL would have to work with recordsets. This is the way that any webpage would display the information that is requested. This will be a very important tool for us to use when using a database connected to our webpages.