This topic is locked

Error with mysql_num_rows

11/23/2011 8:28:15 AM
PHPRunner General questions
G
gbhmayer1 author

Hi
I am using a code in 'before record added' event:
global $conn,$values;
$sql="select * from tbl_person where cod_classroom ='".$values["cod_classroom"]."'";
$result= db_query($sql,$conn);
$num_rows=mysql_num_rows($result);
...
The system returns the following error:'mysql_num_rows() expects parameter 1 to be resource, object given'
Where would I be wrong?

C
cgphp 11/23/2011

The $values array is already available in the "Before record added". Try this version:

global $conn;
$sql="select * from tbl_person where cod_classroom ='".$values["cod_classroom"]."'";
$result= db_query($sql,$conn);
$num_rows=mysql_num_rows($result);
G
gbhmayer1 author 11/23/2011

Thanks for the reply
Unfortunately the error message still persists.

C
cgphp 11/23/2011
global $conn;
$sql="select * from tbl_person where cod_classroom ='".$values["cod_classroom"]."'";
$result = db_query($sql,$conn);
$num_rows = $result->num_rows;
G
gbhmayer1 author 11/23/2011

Thank you very much
It worked perfectly!