sungpeng Posted April 21, 2009 Share Posted April 21, 2009 <?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>  "; } $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 https://forums.phpfreaks.com/topic/154981-search-mysql-and-return-the-result-in-pagination-form/ Share on other sites More sharing options...
The Little Guy Posted April 21, 2009 Share Posted April 21, 2009 Here is one that works, if you want to give it a try (I wrote it): http://beta.phpsnips.com/snippet.php?id=94 Link to comment https://forums.phpfreaks.com/topic/154981-search-mysql-and-return-the-result-in-pagination-form/#findComment-815183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.