我的查询有什么问题 - mysqli_num_rows()期望参数1是mysqli_result,boolean给出

时间:2014-12-03 21:05:39

标签: mysql syntax mysqli

我知道上面的消息发生了错误的MySQL查询,但是我的MySQL查询在这段代码中出了什么问题? 我做了很多研究才找到它,但无法找到解决方案。 表名:pic_msg 列:image_path,ip,index(auto_increment)

<?php
$con = mysqli_connect("localhost","root","password","my_database");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>


<?php
$test_ip = "test-ip";

$sql = "SELECT image_path FROM pic_msg  WHERE ip = '$test_ip' ORDER BY index DESC LIMIIT 1";
$result = mysqli_query($con, $sql);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo $row["image_path"]."<br>";
    }
} else {

}

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:1)

index是一个保留字 - 你应该逃避它。此外,您有一个拼写错误 - 它是limit,而不是limiit

$sql = "SELECT `image_path` FROM `pic_msg` WHERE `ip` = '$test_ip' ORDER BY `index` DESC LIMIT 1";