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

your $sql variable is your mysqli obj
most likely you meant to use $query in your url

if i use $query then all but the first page are blank, no results!

I'm still stuck with this if anyone can help?

Thanks

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.