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'm creating a table to store clients' info via PHP; can I make an inquiry field where the client can enter comments about their inquiry?

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?

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 order the results of my query?

Welcome by regersteration form First name: last name:



Custom Search