我无法使用此代码显示任何结果

时间:2016-08-30 05:02:16

标签: php

我得到“警告:mysqli_num_rows()期望参数1为mysqli_result,布尔值为”当我使用此代码时:

$sql = "SELECT name, time, age FROM friends WHERE age = " .$age. "limit 0, 10";

$secquery = mysqli_query($conn, $sql);

if (mysqli_num_rows($secquery) > 0){

  while($row = $secquery->fetch_assoc()) {
  echo "This person === ".$row['name']. " matched your age, which is " .$row['age']. '<br>';

  }
}

我正在尝试将数据库中的记录与输入的记录进行匹配。我已经尝试了一切。一点帮助?

2 个答案:

答案 0 :(得分:1)

$sql = "SELECT name, time, age FROM friends WHERE age='$age' limit 10";

答案 1 :(得分:0)

你有连接字符串$ conn吗?

 <?php
$conn=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }