Re: limiting rows and pages like google -- again
| From: | Adam | Date: | Thu, 13 Sep 2001 07:01:45 +0000 |
| Subject: | Re: limiting rows and pages like google -- again | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-67150@lists.php.net to get a copy of this message | ||
i spent a good day learning how to do this from scratch. I'll post my code
and you can decypher it yourself.
<?php
$select_all = mysql_query("SELECT id FROM images WHERE
directory='original'");
$select_result = mysql_result($select_all,0);
$select_numrows = mysql_num_rows($select_all);
$i=1;
if (!isset($page)) {
$page = 1;
}
if ($page != 1 ) {
if (($page-1) == 1) {
echo '<a
href="'.$PHP_SELF.'">«previous</a> ';
}else{
echo '<a
href="'.$PHP_SELF.'?page='.($page-1).'">«previous</a> ';
}
} else {
echo '<font color="#999999">«previous</font> ';
}
while ($select_numrows > 0) {
if ($page != $i) {
if ($i==1){
echo '<a
href="'.$PHP_SELF.'">'.$i.'</a> ';
} else{
echo '<a
href="'.$PHP_SELF.'?page='.$i.'">'.$i.'</a> ';
}
} else {
echo '<font color="#999999">'.$i.'</font> ';
}
$i = $i+1;
$select_numrows = $select_numrows-20;
}
if ($page < ($i-1)) {
echo '<a
href="'.$PHP_SELF.'?page='.($page+1).'">next»</a> ';
} else {
echo '<font
color="#999999">next»</font> ';
}
?>
hope this helps. it took 2 days straight to debug and develope. obviously
you would use different database values though.
-Adam
god bless amarica