Jump to content

simple search does not display next


sandbudd

Recommended Posts

Hi guys simple search engine code but when there are more than 10 results it displays the total number of results and displays the first ten but will not click through to the next ten?

 

<?php

  

  $var = @$_GET['q'] ;
  $trimmed = trim($var); 


$limit=10; 


if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }


if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }


mysql_connect("","",""); //(host, username, password)


mysql_select_db("") or die("Unable to select database"); 

$query = "select * from employees where company like \"%$trimmed%\"  
  order by company"; 
  

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);



if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";

  }


  if (empty($s)) {
  $s=0;
  }


  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");


echo "<p>You searched for: "" . $var . ""</p>";



$count = 1 + $s ;


  while ($row= mysql_fetch_array($result)) {
  $title = $row["company"];

  echo "$count.) $title <br>" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);


  echo "<br />";


  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< 
  Prev 10</a>&nbsp ";
  }


  $pages=intval($numrows/$limit);



  if ($numrows%$limit) {

  $pages++;
  }


  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {


  $news=$s+$limit;

  echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  }

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

Link to comment
https://forums.phpfreaks.com/topic/169491-simple-search-does-not-display-next/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.