Accessing Information

Now that we can add information to a database, we need to look at strategies for retrieving the information it contains. As you might guess, you can use mysql_query() to make a SELECT query. How do you use this to look at the returned rows, though? When you perform a successful SELECT query, mysql_query() returns a result resource. You can pass this resource to other functions to access and gain information about a resultset.

Finding the Number of Rows Found by a Query

You can find the number of rows returned as a result of a SELECT query using the mysql_num_rows() function. mysql_num_rows() requires a result resource and returns a count of the rows in the set. Listing 13.4 uses a SQL SELECT statement to request all rows ...

Get Sams Teach Yourself PHP in 24 Hours, Third 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.