I want to count how many results I get when i use my search engine..
Here is my html code:
<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 code:
$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();
Im doing this to know "$pages->items_total = $total;" for my pagination.
Code for display results:
$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 is working fine until, when I search for something that doesn't exist in my databse. So $result = 0. Then I get the fowllowing error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10,10' at line 1
When I change my $result = mysql_query to ==> ("SELECT COUNT(car_id
)FROM adver
");
Then everything works fine exept my pagination numbers... Because I count every car_id, no matter what I'm searching.. I'm getting for exampple 3 empty pages..
I hope someone can help me with this problem,Thanks