I've been following several tutorials in order to build a simple search engine for my website. But I can't seem to be able to do pagination I.E show results by pages (10 per page).

I'll list the code I have thus far and hopefully if there's someone well versed with this stuff can fill in/advise me on how to add the pagination.

Here's the code:

<?php
  $var = @$_GET['q'] ;
  $search = trim($var); //trim whitespace 
  $limit = 10;

require_once("connect.php");

 $query = "SELECT * FROM table WHERE value LIKE \"%$search%\""; 

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
  
  if ($numrows > 0) //do following if there are results to show
  {
  
  // if s hasn't been passed to script, use 0
  if (empty($s)) {
  $s=0;
  }
  $count = 1 + $s ;

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");
  
  while ($row = mysql_fetch_array($result)) { 
  $count++;
  $title = $row["title"];
  echo $title;
}

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "About $b to $a of $numrows results";
  ?>
  }
?>

This is for part of a coursework and I have a deadline to meet so it would be great if someone can offer some help soon!

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.