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

how to write sessions in php code?

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

I am unable to make pages for my search result.Below I am giving the code that I am using. Career Search result Yami says

How do I access the current time with mysql?

How do I find the number of rows affected by a query?



Custom Search