How do I find the number of rows in a result set?
Here's how it is done, using the mysql_num_rows function which does what it says on the tin.
<?php
$query = "SELECT friends FROM listoffriends WHERE name = 'me'";
$doquery = mysql_query($query);
$myfriendnumber = mysql_num_rows($doquery);//returns integer value
if(!$myfriendnumber) { echo "Sorry, the person 'me' doesn't have any friends"; }
else { echo "The person 'me' has $myfriendnumber friends!"; }
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More mysql PHP Questions
Why will this statement not print a column with "lastname space firstname"? Print " .$info['businessname'] "; Print " .$info['firstname']. " " .$info['lastname'] "; I want to see 2 columns - ahow to write sessions in php code?
How do I return a random row from the database?
How do I order the results of my query?
Why does this code not work? Returns this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ClaimNo = AND UserName = john' at line 2
