我爲我的搜索結果使用了分頁,但由於某種原因,我的分頁與我的搜索腳本無法正常工作。我似乎無法找到將LIMIT $start, $display
放入我的搜索查詢代碼中的正確位置,而我將其放入代碼中時,它顯示的分頁全都是錯誤的。有人可以幫幫我嗎?MySQL LIMIT問題
這是我的PHP & MySQL搜索代碼的一部分。
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
mysqli_select_db($mysqli, "sitename");
$search_explode = explode(" ", $search);
foreach($search_explode as $search_each) {
$x++;
if($x == 1){
$construct .= "article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
} else {
$construct .= "OR article_content LIKE '%$search_each%' OR title LIKE '%$search_each%' OR summary LIKE '%$search_each%'";
}
}
$construct = "SELECT users.*, users_articles.* FROM users_articles
INNER JOIN users ON users_articles.user_id = users.user_id
WHERE $construct";
$run = mysqli_query($mysqli, $construct);
$foundnum = mysqli_num_rows($run);
SQL語句。
SELECT users.*, users_articles.* FROM users_articles INNER JOIN users ON users_articles.user_id = users.user_id WHERE article_content LIKE '%find%' OR title LIKE '%find%' OR summary LIKE '%find%'OR article_content LIKE '%this%' OR title LIKE '%this%' OR summary LIKE '%this%'OR article_content LIKE '%article%' OR title LIKE '%article%' OR summary LIKE '%article%' LIMIT 0, 10
添加'$ search_each = mysqli_real_escape_string($ mysqli,$ search_each);'會很好。或者使用準備好的語句 – 2010-07-21 06:31:56