Re: counting ..
| From: | Justin French | Date: | Tue, 25 Mar 2003 07:45:35 +0000 |
| Subject: | Re: counting .. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-140922@lists.php.net to get a copy of this message | ||
Use $num as a global value across all pages, through GET, and use $i for a
per-script counter. Increase both in a loop, add some navigation, and
you're all set...
This should be a starting point...
<?
$total_num = 137;
$per_page = 25;
// find value of $num, or start from zero
if(isset($_GET['num'])) { $num = $_GET['num']; } else { $num = 0; }
$i = 0;
while( ($i < $per_page) && ($num < 137) )
{
// increase "global" counter
$num++;
// increase "local" counter
$i++;
// do something here 25 times
echo "{$i} - {$num} <br />";
}
$last = $_GET['num'] - $per_page;
if($num > $per_page) {
echo "<a href='{$_SERVER['PHP_SELF']}?num={$last}'>last
{$per_page}</a>";
echo " | ";
}
if($num < $total_num) {
echo "<a href='{$_SERVER['PHP_SELF']}?num={$num}'>next
{$per_page}</a>";
}
?>
Cheers,
Justin French
on 25/03/03 5:09 PM, Sebastian (sebastian@dslr.net) wrote:
> Hello all.
>
> rather dumb question.
>
> I have a pagination system, 25 results per page, which are user comments, I
> want to put a number on each comment so i am doing something like:
>
> $num=$num + 1;
> $number = $num;
> echo $number;
>
> But when i switch to the next 25 results it starts counting from 1 again,
> LoL.
>
> So i have to use $_GET right? If so can someone give me an example.
>
> Thanks in advanced.
>
>
> cheers,
> - Sebastian
>