MySQL mysql_num_rows();

wesslayneb picture wesslayneb · Dec 19, 2013 · Viewed 27.5k times · Source

I am not sure as to why. But the code I have created below is not working. The variable: "$num_rows" is not even being set and has no value (not even 0). Anyone know as to why this issue is occurring?

$result2 = mysql_query("SELECT * FROM `mycity_vehicles` WHERE `id` = '$vehID'");
while($row2 = mysql_fetch_array($result2))
$num_rows = mysql_num_rows($result2);
{
    if(empty($num_rows)) {
        echo "empty";
    }
    else {
        echo $num_rows;
    }

Answer

John Conde picture John Conde · Dec 19, 2013

Your syntax is off.

while($row2 = mysql_fetch_array($result2))
$num_rows = mysql_num_rows($result2);
{

should probably be

$num_rows = mysql_num_rows($result2);
while($row2 = mysql_fetch_array($result2))
{