MySQL mysql_num_rows();

时间:2013-12-19 18:40:29

标签: php mysql mysql-num-rows

我不确定为什么。但是我在下面创建的代码不起作用。变量:“$ num_rows”甚至没有被设置并且没有值(甚至不是0)。任何人都知道为什么会出现这个问题?

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

2 个答案:

答案 0 :(得分:2)

您的语法已关闭。

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

应该是

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

答案 1 :(得分:2)

你做错了订单。

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