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 am unable to make pages for my search result.Below I am giving the code that I am using. Career Search result Yami says

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?

How do I connect to mySQL from PHP?

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

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



Custom Search