Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count of records returned needed in PHP script 1

Status
Not open for further replies.

peterv6

Programmer
Sep 10, 2005
70
US
In the query below, I'm selecting all records in a table, in the future, I may be only selecting a few record from th table.

Is there a way to get the count of records returned by the query, so that I can base what I do next on that count?
Thanks!

$query ="select * from usersTable";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
while ($newArray = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $newArray['id'];
$username = $newArray['username'];
$password = $newArray['password'];
echo "ID is ".$id.
"<br/>Username: ".$username.
"<br/>Password: &nbsp ".$password.
"<br/>--------------------------------------------<br/>";
}
}
}

PETERV
Syracuse, NY &
Boston, MA
 
This is a PHP question better asked in forum434

$rows=mysql_num_rows($result); will return the number of rows produced by the query.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you vacunita, this is exactly what I was looking for.

PETERV
Syracuse, NY &
Boston, MA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top