Jump to content

search mysql and return the result in pagination form


sungpeng

Recommended Posts

<?php
  
  
  $var = @$_GET['address'] ;
  $trimmed = trim($var); 
  $limit=10; 


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



include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php");




$going="$trimmed"; 
$query = "select * from listings where address like \"%$going%\" order by rid"; 
$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>";

  echo "<p><a href=\"http://www.google.com/search?q=".$trimmed."\" target=\"_blank\" title=\"Look up".$trimmed." on Google\">Click here</a> to try the search on google</p>";
  }

  if (empty($s)) {
  $s=0;
  //set variable
  }




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


  echo "<p>You searched for: "" . $var . ""</p>";
  echo "Results";
  $count = 1 + $s ;


  while ($row= mysql_fetch_array($result)) {
  $title = $row[room];
  $title2 = $row[rid];
  $title3 = $row[type];
echo "<br/>$count. <a href='http://www.sgfairdeal.com/housing/update.php?rid=$row[rid]'>$title3</a> $title room"; 
  $count++ ;
  }


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



  
  if ($s>=1) { 
  $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>";
  
?>

 

Found the above code online. The "NEXT" 10 results button is not working. It can only view 10 results currently on first page. I need a code that can search mysql and return the result in pagination form.  Anyone can help?

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.