0

I have a simple form to search a table for the search term entered into that form.

$query = $_GET['term'];
$min_length = 1;
if(strlen($query) >= $min_length){
   $query = htmlspecialchars($query);
   $query = mysqli_real_escape_string($link, $query);
}

Here the variable 'query' is the search query posted using the get method from the form.

The query for the database looks like this

$sql=mysqli_query($link, "SELECT COUNT(id) FROM products WHERE `name` LIKE 
'%".$query."%' OR `brand` LIKE '%".$query."%'
OR `description` LIKE '%".$query."%' OR `spec` LIKE '%".$query."%'
OR `category` LIKE '%".$query."%' OR `subcategory` LIKE '%".$query."%' AND status = 1 
ORDER BY id DESC") OR die(mysqli_error($link));

So this works ok if I dont paginate results, but I need to paginate them.

I think I need to get this line of code to send the query to each paginated page.

echo " <a href='{$_SERVER['PHP_SELF']}?$sql¤tpage=$x'>$x</a> ";

This gives me this error

'Catchable fatal error: Object of class mysqli_result could not be converted to string'

'$x' is just the variable for the current page

Can anyone help?

Thanks for looking

2
Contributors
4
Replies
35
Views
3 Years
Discussion Span
Last Post by GlenRogers
0

Sorted (I think)

I had everything wrapped in a

if(isset( $_GET['submit'] ) ){
}

So it appears to me that when I went to any other page but the first page (the first time) that submit from my search form wasn't being posted again obviously, so there were no results to get.

When I took that 'if' out the pagination works. But is it ok not to have it?

Thanks

Edited by GlenRogers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.