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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.