tags:

views:

224

answers:

4
+1  A: 

i use mysql_num_rows http://php.net/manual/en/function.mysql-num-rows.php

<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>
Carter Cole
You can't use the mysql_* functions with PDO, unfortunately.
Alex JL
A: 

Well, you are missing the "$" in front of num_rows (i.e. it should be "$num_rows"). That could be it.

brookmarker
It's object property syntax, actually, not a variable. So if $result had a num_rows property (which it doesn't, I guess) that would be the correct form, no $.
Alex JL
A: 

I would suggest simply

$num_results = count($result);
Alex JL
+1  A: 

I'm taking a guess you're using some type of MySQL wrapper? If so change $num_results = $result->num_rows; to $num_results = $dbh->num_rows; assuming that num_rows is a method of $dbh. If this doesn't work, then you could use $num_results = count($result);.

I'm not sure what wrapper you're using so I have no idea if the above code will work.

Jesse