Re: Paging Help

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

 



Juanjo Pascual wrote:
> <?php
> // Num of records each time
> $NUM_RECORDS = 10;
> 
> if ($_GET["pag"] == "") {
>    $ini = 0;
>    $pag = 1;
> }
> else {
>    $ini = ($pag - 1) * $NUM_RECORDS;
> }
> 
> // Query to show
> $query_rsData = "SELECT * FROM table LIMIT " . $ini . ", " . $NUM_RECORDS;
> $rsData = mysql_query($query_rsData, $DB_CONECTION);
> 
> // Total records
> $query_rsData2 = "SELECT * FROM table";
> $rsData2 = mysql_query($query_rsData2, $DB_CONECTION);
> $num_total_records = mysql_num_rows($rsData2);
> 

    Since you query all enregs from table why not query all first and
the do mysql_data_seek on result?

 // Query to show
 $query_rsData = "SELECT * FROM {table} ORDER BY {Whatever field}";
 $rsData = mysql_query($query_rsData, $DB_CONECTION);
 $num_total_records = mysql_num_rows( $rsData );

 $total_pag = ceil($num_total_records / $NUM_RECORDS);

 if( $pag < 1 )
     $pag = 1;
 elseif( $pag > $total_pag )
     $pag = $total_pag;

 $start_enreg = ($pag-1) * $NUM_RECORDS;

 @mysql_data_seek( $rsData, $start_enreg );

 while( ($result = mysql_fetch_object( $rsData )) )
 {
    // display data...
 }

> // Total pages
> $total_pag = ceil($num_total_records / $NUM_RECORDS);
> 
> $previous_page = $pag - 1;
> $next_page = $pag + 1;
> ?>
> 
> Links for the pages
> -------------------
> 
> First page: this_page.php?pag=1
> Previous page: this_page?pag=<?php echo previous_page; ?>
> Next page: this_page?pag=<?php echo next_page; ?>
> Last page: this_page?pag=<?php echo total_pag; ?>
> 
> 
> Rodrigo de Oliveira Costa escribió:
>> I have the following problem, I need to make a paging system to show
>> results from search on a      Mysql database. I found a class that
>> should do the job but couldn't figure it out how to use it. Does
>> anybody has an Idea of hos to do this? I thank in advance for any help
>> you guys can provide me.
>> Rodrigo
>>
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux