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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using mysql_num_rows

Status
Not open for further replies.

boab

Programmer
Joined
May 30, 2001
Messages
75
Location
GB
Can anyone help here

The code I'm using finds the total number of records

function trawl(){

$qTrawl = "SELECT * FROM feedback ";

$rTrawl = mysql_query($qTrawl);
$num = mysql_num_rows($rTrawl);

return $num;
}

calculates the percentage of a particular response to a question

function perc($criteria,$value,$total){

$qPerC = "SELECT * FROM feedback WHERE $criteria = $value";

$rPerC = mysql_query($qPerC);
$q_Num = mysql_num_rows($rPerC);

if (q_Num<1)
{
percentage = 0;
}else
percentage = ($q_Num/$total)*100
}

return $percentage;
}

these two are called on the page thus:

<?php perC("4a","Very",trawl());?>

when the page is processed I get 3 warnings two relate to the use of mysql_num_rows saying that the supplied argument is not valid the third warning is a divide by zero caused by the previous two errors.

ANy Ideas how to fix this.


THe Start of wisdom is to realise you know nothing. I must be a genius then!
 
A common reason for mysql_num_rows() not working is that mysql_query() barfed for some reason and returned a FALSE rather than a result handle.

Change:
$rTrawl = mysql_query($qTrawl);
and
$rPerC = mysql_query($qPerC);

to read:
$rTrawl = mysql_query($qTrawl) or die(mysql_error());
and
$rPerC = mysql_query($qPerC) or die(mysql_error());

respectively.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top