PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I find the number of rows in a result set?


If is often useful to know how many rows are returned, and particularly when there may be no rows returned so that you can deal with that accordingly and tell the user to widen their search or try a different search, perhaps.

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!"; }
?>



ASK A QUESTION

More mysql PHP Questions

I need to test database time needed to execute scryp (like 10 000 inputs) with what command i can start measuring time, start scrypt, and then to stop time when scrypt is done and get time resault?

the uploading status shows success but not showing in the server is empty the written php file is first gave warning cannot uploaded warning in foreach loop but i corrected mistake by keeping above if condition and no error status shows success upload b

How do I order the results of my query?

How do I set a default value for ENUM fields in PHP?

How do I insert the date into my table?



Custom Search