At 11:37 2001-09-21 -0700, Alawi Albaity wrote:
>I have a table ..
>this table have 20 record..
>I want to view this record in the 4 pages (5 record by
>page)..
The following should get you going in the right direction. As shown, this
works on PHP3 as well as PHP4:
<?PHP
$mytable = array( .... );
$pagesize = 5 ; // records per page
$tablesize = count( $mytable );
$tablestart = 0 ;
if ( isset( $pageindex ) )
{
// url to this page was specified with an offset
$tablestart = ($pageindex -1 ) * $pagesize ;
}
else
{
$pageindex = 1 ;
}
if ( ( $tablestart > $tablesize ) || ( $tablestart < 0 ) )
{
// something is wrong - visitor probably screwing with their
// URL. You could display an error -- or just reset to page 1
$pageindex = 1;
$tablestart = 0;
}
// some function to print your table from the defined startpoint
to the
// number of elements to print, checking for possible array
termination
// within this range (i.e. if the array doesn't fall on an exact
// pagesize boundary, there may not be a full table here).
// yup, YOU get to do some of your own work - your question was how to
// deal with putting the data on separate pages, not how to
display it.
displaymytable( $mytable, $tablestart, $pagesize )
// emit "previous" and "next" links (or you might display a whole
// range of direct page links).
if ( $pageindex > 1 )
{
print( '<a href="' . $PHP_SELF . '?pageindex=' );
print( $pageindex - 1 . '">Prev</A>');
}
if ( ( $tablestart + $pagesize ) < $tablesize )
{
print( '<a href="' . $PHP_SELF . '?pageindex=' );
print( $pageindex + 1 . '">Next</A>');
}
?>
---
Please DO NOT carbon me on list replies. I'll get my copy from the list.
Sean B. Straw / Professional Software Engineering
Post Box 2395 / San Rafael, CA 94912-2395
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]