At 4/30/2002, you wrote:
>Any one know how to display, go to page number on a record list page
>
>eg
>
><Prev 1|2|3|4|5|6....... Next>

Here's a very simplified demo of dropdown+arrows paging code I did for my 
gallery software.
It might not be the most clever code around, but it works, and scales well.

All you need to edit is the main query, couple fo arrow images, and 
database connect code to make it run.  It now "feeds itself", so you might 
want to change that, too.
Live demo is e.g. http://photography-on-the.net/gallery/list.php?exhibition=1

----------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
         <title>Paging demo by P.S.</title>
</head>
<body>

<?php
// total has to be a value queried from database (=how many results?),
// but to make this code shorter let's give it some value for this demo:
$total = "122";
// set global SERVER variable for different versions of PHP
if (isset($_SERVER)) $PHP_SELF = $_SERVER['PHP_SELF'];

// connect to the database with this file:
include ("connect.php");

if (isset  ($HTTP_POST_VARS['perpage']))
{$perpage = $HTTP_POST_VARS['perpage'];
}
if (isset ($HTTP_POST_VARS['offset']))
{$offset = $HTTP_POST_VARS['offset'];
}
if (isset  ($HTTP_GET_VARS['perpage']))
{$perpage = $HTTP_GET_VARS['perpage'];
}
if (isset ($HTTP_GET_VARS['offset']))
{$offset = $HTTP_GET_VARS['offset'];
}
if (!isset ($perpage))
{$perpage = "10";
}
if (!isset ($offset))
{$offset = "0";
}

$fetchlist = mysql_query(
"
SELECT
         *
FROM
         your_table
LIMIT
         $offset,$perpage
"
         );
if (!$fetchlist) {
         $queryname = "fetchlist";
         include("db_error.php");
}
?>

<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="POST" 
name="FORM_page_change" id="FORM_page_change">
<input type="hidden" name="offset" value="<?php print $offset; ?>">
<input type="hidden" name="perpage" value="<?php print $perpage; ?>">
<input type="hidden" name="JS_SUBMIT_page_change" value="yep">
<table border="0" cellspacing="3" 
cellpadding="0"><tr><td>&nbsp;&nbsp;</td><td><?php

// PREV PAGE LINK WITH VERIFICATION
$prevlink = $offset-$perpage;
if ($prevlink<=0) $prevlink=0;
print "<a href=\"" . $PHP_SELF;
print "?offset=" . $prevlink . "&perpage=" . $perpage;
print "\"><img src=\"../graphs/left.gif\" width=\"14\" hspace=\"1\" 
height=\"16\" border=\"1\" alt=\"previous page\"></a>";
print "</td><td>";
print "<select name=\"offset\" onchange=\"function_submit_page_change()\" 
style=\"border: 0px none;\">";
print "\r";


// THIS CODE BUILDS THE DROPDOWN MENU FOR PAGE SELECTION
$page = 1;
for ($i=0; $i<=$total-1; )
{
                 print "<option value=\"";
                 print $i;
                 print "\"";
                 if ($offset==$i) {print " selected";}
                 print ">Page ";
                 print $page . "&nbsp; ";
                 print "</option>";
                 print "\r";
         $i=$i+$perpage;
         $page++;
}
print "</select>";
print "\r";
print "</td><td>";


// NEXT PAGE LINK WITH VERIFICATION
$nextlink = $offset+$perpage;
if ($nextlink>=$total) $nextlink=$offset;
if ($nextlink<=0) $nextlink=0;
print "<a href=\"" . $PHP_SELF;
print "?offset=" . $nextlink . "&perpage=" . $perpage;
print "\"><img src=\"../graphs/right.gif\" width=\"14\" height=\"16\" 
border=\"1\" alt=\"next page\"></a>";
print "</td><td>";


// JAVASCRIPT FOR THIS FORM
?>
<script language="JavaScript" type="text/javascript">
<!--
function function_submit_page_change(){
document.FORM_page_change.submit();
         }
//-->
</script>
<noscript>
<?php
//NON JAVASCRIPT MENU FOR BROWSERS WITHOUT JAVASCRIPT
print "<input type=\"image\" src=\"../graphs/jump_to.gif\" alt=\"jump to 
selected page\" name=\"SUBMIT_page_change\">";
?>
</noscript>

</td></tr></table>

<?php
Print "<p><b>You successfully listed results from " . $offset . " to " . 
($offset+$perpage) . "</b>";
?>

</body>
</html>

----------------------------------------------

Cheers,
Pekka
http://photography-on-the.net/



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

Reply via email to