Forum Moderators: coopster

Message Too Old, No Replies

Counting the number of results from a query

Trouble with displaying different responses

         

Jamier101

7:29 am on Sep 28, 2010 (gmt 0)

10+ Year Member



I have a script for counting the number of rows that have been found during a query. However, it doesn't seem to work correctly. I'm trying to display a different line of text for a single result to a response with multiple results.


//see if the query returned anything ie > 'more than' 0 rows
if(mysql_num_rows($query) > 0){

//loop through the results
echo "Search conducted on: ";
echo date("l, F d, T h:i" ,time());
echo "<p>";

$result_rows = mysql_num_rows($query);

if($result_rows = 1){
echo '<div> ' . $result_rows . ' villa was found, here are your results:</div>';
(
else{
echo '<div> ' . $result_rows . ' villa(s) were found, here are your results:</div>';
}

Anyango

11:12 am on Sep 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jamier

are you sure you wana run mysql_num_rows on a $query ? It has to be run on a query's result.

try like this

$result=mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){

Jamier101

4:49 pm on Sep 28, 2010 (gmt 0)

10+ Year Member



Thanks, it finally works :)


//loop through the results
echo "Search conducted on: ";
echo date("l, F d, T h:i" ,time());
echo "<p>";

if(mysql_num_rows($query) == 1) {
echo '<div> ' . mysql_num_rows($query) . ' villa was found, here are your results:</div>';
}
else{
echo '<div> ' . mysql_num_rows($query) . ' villa(s) were found, here are your results:</div>';
}