There's no limit clause in your SQL statement. You actually have to run two SQL statements. You have the choice of: 1. Run one statement returning all records like this "select count(*) from ..." without the limit clause. Use that to get the total records. Then run "select * from ... limit $page*$max, $total" to get the list to display. 2. Run one statement "select SQL_CALC_FOUND_ROWS * from ... ... limit $page*$max, $total" to get the list to display. Then run "select FOUND_ROWS()" to get the number that would have been returned without the limit clause. MySQL documentation tends to point you to using #2. However, there are some articles where the two were compared and found that #1 seems to perform much better. See this... http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/ Hope that helps. On Thu, Feb 18, 2010 at 3:35 AM, Gab Teo <doneatlast1000@xxxxxxxxx> wrote: > > > I have a problem with this search script as it return all the information > in the database when I search for any term,I set the pagenation to a limit > of 10, but I can't firgure out why the set limit is not working. Can any one > with an eagle eyes spot the error please? > > Gab > > <?php > if(!empty($_GET[Submit])) > { > include("databaseconfig.php"); > $term=$_GET['term']; > if($term == "") > { > echo "<p>Please enter a search...</p> "; > exit; > } > else > { > echo "Your Search Result<br>"; > "<p>"; > } > } > $pagenum = 1; > {$pagenum=$_POST[page];} > $rowsperpage = 10; > $offset=($pagenum-1)*$rowsperpage; > > $numrows=$row[numrows]; > $maxPage=ceil($numrows/$rowsperpage); > $sql=mysql_query("select * from selling where product like '$trimmed%' or > description like '$trimmed%' or price like '$trimmed%' or info like > '$trimmed%' or contactseller like '$trimmed%' order by id DESC "); > if (mysql_num_rows($sql)==0) > echo " No result"; > else > { > while ($result=mysql_fetch_array($sql)) > { > $id=$result[id]; > $product=$result[product]; > $description=$result[description]; > echo "<a href=fullsearch.php?id=$id>".$result[product]."</a><br>"; > echo "$result[description]"; > echo "<p>"; > } > > $pageno=$pagenum+1; > $prev=$pagenum-1; > $penultimate=$maxPage-1; > if($pagenum==$maxPage and $maxPage>1) > { > echo "<center>"; > echo "[ <a href=search.php?page=$prev>PREVIOUS PAGE</a> ]"; > echo " "; > echo "[ <a href=search.php?page=1>FIRST PAGE</a> ]"; > echo "</center>"; > } > elseif($pagenum<$maxPage and $pagenum==1) > { > echo "<center>"; > echo "[ <a href=search.php?page=$pageno>NEXT PAGE</a>]"; > echo " "; > echo "[ <a href=search.php?page=$maxPage>LAST PAGE</a>]"; > echo "</center>"; > } > elseif($pagenum<$maxPage and $pagenum>1) > { > echo "<center>"; > echo "[ <a href=search.php?page=1>FIRST PAGE</a> ]"; > echo " "; > echo "[ <a href=search.php?page=$pageno>NEXT PAGE</a> ]"; > echo " "; > echo "[ <a href=search.php?page=$prev>PREVIOUS PAGE</a> ]"; > echo " "; > echo "[ <a href=search.php?page=$maxPage>LAST PAGE</a> ]"; > echo "</center>"; > } > else > echo "<center>This is the only page</center>"; > echo "<center>Showing page $pagenum of $maxPage</center>"; > > } > > ?> > > > [Non-text portions of this message have been removed] > > > [Non-text portions of this message have been removed] ------------------------------------ Are you looking for a PHP job? Join the PHP Professionals directory Now! http://www.phpclasses.org/jobs/ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-objects/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/php-objects/join (Yahoo! ID required) <*> To change settings via email: php-objects-digest@xxxxxxxxxxxxxxx php-objects-fullfeatured@xxxxxxxxxxxxxxx <*> To unsubscribe from this group, send an email to: php-objects-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/