Re: Pagenation Set up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brian is mentioning about the mysql LIMIT, check the documentation what it does. 

or for quick reference check this out http://php.about.com/od/mysqlcommands/g/Limit_sql.htm




________________________________
From: Gab Teo <doneatlast1000@xxxxxxxxx>
To: php-objects@xxxxxxxxxxxxxxx
Sent: Fri, February 19, 2010 12:14:43 AM
Subject: Re:  Pagenation Set up

  
The script is returning every data on the recordset even while I set the limit to a limit of 10 as in ($rowsperpage = 10;)

--- On Thu, 2/18/10, Brian H <brianh781@gmail. com> wrote:

From: Brian H <brianh781@gmail. com>
Subject: Re:  Pagenation Set up
To: php-objects@ yahoogroups. com
Date: Thursday, February 18, 2010, 1:22 PM

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.mysqlper formanceblog. 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@ yahoo.com> 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("databaseco nfig.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[descript ion];
> echo "<a href=fullsearch. php?id=$id> ".$result[ product]. "</a><br> ";
> echo "$result[descriptio n]";
> 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

[Non-text portions of this message have been removed]


 


      

[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux