Retrieving Query Results
In the preceding section of this chapter I discussed and demonstrated how to execute simple queries on a MySQL database. A simple query, as I’m calling it, could be defined as one that begins with INSERT, UPDATE, DELETE, or ALTER. What all four of these have in common is that they return no data, just an indication of their success. Conversely, a SELECT query generates information (i.e., it will return rows of records) that has to be handled by other PHP functions.
The primary tool for handling SELECT query results is mysql_fetch_array(), which takes the query result variable (that I’ve been calling $result) and returns one row of data at a time, in an array format. You’ll want to use this function within a loop that ...
Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.