...Beauty, cleaning, DIY tips and more - free to join!
   Login   Contact us   Site map   Puzzle Club   Ask a question    Newsletter

How To Find Number Of Rows Returned: MySQL

Computing : Learning PHP

Using mySQL there are many helper functions that tell you for instance how many rows are returned by a query.

Thus if you issue this query:

$whatever = mysql_query("SELECT * FROM members");

then to see how many rows are returned there we can do this:

$rows_returned = mysql_num_rows($whatever);

and we now know how many rows.

This is useful if we want to display different info if no rows are returned and not for instance construct a table to hold returned data.

Since if there are no rows returned then the variable will evaluate to 0 and therefore false, you could do this:

if (!$rows_returned = mysql_num_rows($whatever)) {
echo "Sorry, no results";
}
else {
// process data returned
}


By: Stephen

Share on Facebook: On Twitter: TwitterTweet this!

  Reply to How To Find Number Of Rows Returned: MySQL

  Receive Our Newsletter




Questions about PHP and mySQL:

Ask question

More Articles:
How to meet people with similar interests
How to geo-target adverts
How to copy a DVD