简体   繁体   English

PHP MySQLi numrow输出1,即使该值大于或小于1

[英]PHP MySQLi numrows outputs 1 even if the value is higher or lower than 1

I have this PHP script, which outputs the variable inside the lr column: 我有这个PHP脚本,该脚本在lr列中输出变量:

$conx = mysqli_connect("value here", "value here", "value here", "value here");
$sql = "SELECT lr FROM locations";

if (mysqli_connect_errno($conx)){
    die("Failed to connect to MySQL: " . mysqli_connect_error());
    }
        $query = mysqli_query($conx, $sql);
        $numrows = mysqli_num_rows($query);
        if ($numrows > 1) {
            echo "No locations found";
        } elseif ($numrows == '1') {
            echo "1 location found";
        } elseif ($numrows > 0) {
            echo $numrows." locations found";
        }
        // Free result set
        mysqli_free_result($query);

mysqli_close($conx);

Everything seems to work fine, but when it outputs the result it always outputs 1 even if the value is higher or lower than 1 一切似乎都做工精细,但是当它输出的结果总是输出1 ,即使该值高于或低于1

Anyone with a solution? 有人解决吗?

Try this, see if it suits your goal: (this is a very basic example) 试试看,看它是否符合您的目标:(这是一个非常基本的示例)

$conx = mysqli_connect("value here", "value here", "value here", "value here");
$sql = "SELECT lr FROM locations";

if (mysqli_connect_errno($conx)){
    die("Failed to connect to MySQL: " . mysqli_connect_error());
    }
$query = mysqli_query($conx, $sql);
    while($row=mysqli_fetch_array($query);)
        {
            echo $row['lr']." ";
        }

mysqli_close($conx);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM