-1

我尝试使用 mysql_num_rows 函数计算 num_rows,但一直出现错误。我的查询没有错误。可能是什么问题呢

<?php

if(isset($_POST['search'])){

$search = $_POST['search'];
// connect to database
$con = mysqli_connect("localhost", "root","", "ajax") or die ("could not connect to    database");

$query = "SELECT * FROM searchengine  WHERE title LIKE '%$search%' ";
$get_query = mysqli_query($con, $query) or die("can't execute query");
$rows = mysqli_fetch_array($get_query);

$num = mysql_num_rows($get_query);
echo $num;

while($row = mysqli_fetch_array($get_query)){
echo "resuslts found ".'<br/>';
echo $row['title'];


}


}
else{
echo " not set";
}



?>
4

4 回答 4

1

您正在混合 mysqli (注意i)和 mysql 函数。这两个库不可互换,并且其中一个的结果不能在另一个中使用。

代码应该是:

$num = mysqli_num_rows($get_query);
            ^----
于 2013-06-18T14:48:50.587 回答
1

尝试mysqli

$num = mysqli_num_rows($get_query);
于 2013-06-18T14:49:18.833 回答
0

您的 $get_query 使用 mysqli 语法,而另一方面,您在 mysql 中使用 $num .. 尝试使用相同的格式。它应该工作。

于 2013-06-18T14:48:22.300 回答
0

尝试这个 :

if(isset($_POST['search'])){

$search = $_POST['search'];

// connect to database

$con = mysqli_connect("localhost", "root","", "ajax") or die ("could not connect to    database");

$query = "SELECT * FROM searchengine  WHERE title LIKE '%$search%' ";

$get_query = mysqli_query($con, $query) or die("can't execute query");

$num = mysqli_num_rows($get_query);

echo $num . "resuslts found ".'<br/>';

while($row = mysqli_fetch_array($get_query)){

echo $row['title'];

}

}

else{

echo " not set";

}
于 2013-06-18T15:01:12.037 回答