我創建的搜索和檢索在數據庫中的數據的搜索功能,但得到這個錯誤mysqli_num_rows()預計參數1是
mysqli_num_rows()預計參數1至 線16
可以mysqli_result PHP mysqli_result PHP
這裏是我的PHP代碼
<?php
include 'database_conn.php';
//collect search title
if (isset($_GET['keywords'])){
$searchq = $_GET['keywords'];
$searchq = preg_replace("#[^a-z0-9]#i" , "", $searchq);
$query = "SELECT eventTitle FROM te_events WHERE eventTitle LIKE '%searchq%'";
mysqli_query($conn, $query)
or die ("SQL error:" .mysqli_error($conn));
$count = mysqli_num_rows($query);
if($count==0){
echo "<p>There was no search result!</p>\n";
}
else{
while ($row = mysqli_fetch_array($query)){
$title = $row['eventTitle'];
$id = $row['eventID'];
echo "<p>title</p>\n";
}
}
}
?>
有沒有在我的代碼的任何問題???
$查詢替換你的代碼是一個字符串。你需要使用從mysqli_query()返回的mysqli_query() – e4c5
mysqli_query($ conn,$ query)將這行改爲這個** $ Myresult = mysqli_query($ conn,$ query)**並使用** $ Myresult **即結果設置爲統計num rows.ie $ count = mysqli_num_rows($ Myresult); –