我想我算多少結果獲得當我使用我的搜索引擎..
這裏是我的html代碼:
<form id="header-search" action="car-list.php" method="get">
<input type="text" name="search" id="text" placeholder="Zoek hier.." class="quick-search" > </form>
PHP代碼:
$searchq = $_GET['search'];
$searchq = str_replace(' ','-',$searchq);
$con = mysql_connect("localhost","root","****");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("register-login", $con);
$result = mysql_query("SELECT COUNT(`car_id`)FROM `adver` WHERE merk LIKE '%$searchq%' OR titel LIKE '%$searchq%' OR model LIKE '%$searchq%'");
$row = mysql_fetch_array($result);
$total = $row[0];
$pages = new Paginator;
$pages->items_total = $total;
$pages->mid_range = 5;
$pages->paginate();
林這樣做是爲了知道 「$ pages-> items_total = $總量;」爲我的分頁。
代碼顯示結果:
$searchq = htmlspecialchars($searchq);
$searchq = mysql_real_escape_string($searchq);
$photo=mysql_query("SELECT * FROM `adver` WHERE merk LIKE '%$searchq%' OR titel LIKE '%$searchq%' OR model LIKE '%$searchq%' ORDER BY car_id DESC $pages->limit")or die(mysql_error());
while($get_photo=mysql_fetch_array($photo)){
?>
<a href="<?php echo 'car-details.php?merk='.$get_photo['merk'] .'&car_id=' .$get_photo['car_id'] .'&titel=' .$get_photo['titel'] ;?>">
<img src="<?php echo $get_photo['path'] ; ?>" style="border:1px solid #021a40;" alt="<?php echo $get_photo['merk'] ;?>" }/>
Everyyhing工作正常,直到當我尋找的東西並不在我的DATABSE存在。所以$ result = 0.然後我得到了錯誤的結果:
你的SQL語法錯誤;檢查與您的MySQL服務器版本對應的手冊,在第一行'-10,10'附近使用正確的語法
當我將$ result = mysql_query更改爲==>(「SELECT COUNT(car_id
)FROM adver
「); 然後,一切工作正常免除我的分頁號碼...因爲我計算每一個car_id,無論我正在尋找..我得到檢查3空頁..
我希望有人可以幫助我這個問題,謝謝
One addition tipp:使用mysqli而不是mysql函數並讀一些關於準備好的語句! – Gerifield