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
How do I insert the date into my table?How do I find the number of rows affected by a query?
I am extracting data from a MySQL Database of which one of the data stored is seperated by a comma. For example, step1,go here,step 2,go there,step 3,go back etc etc. I want to know how to split the data at the comma and format it in html. Using the split
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
