Search code examples
phpmysqlmysql-num-rows

MySQL mysql_num_rows();


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;
    }

Solution

  • 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))
    {