php MySQL mysql_num_rows();

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20689246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:25:23  来源:igfitidea点击:

MySQL mysql_num_rows();

phpmysqlmysql-num-rows

提问by wesslayneb

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?

我不知道为什么。但是我在下面创建的代码不起作用。变量:"$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;
    }

采纳答案by John Conde

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

回答by Orel Eraki

You did it the wrong order.

你做错了顺序。

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