Forum Moderators: coopster
for several different .php files (file1, file2, file3 ...) i want to have page numbering, ie, this is page 1, this is page 2...
the files are accessed in different order
order 1: file1, file2, file3
order 2: file2, file3, file1
but the page numbering should always be 1, 2, 3 regardless of actual file order ...
any ideas how this can be done?
thanks
m
If you're presenting them as links in a list that you're ordering somehow, you could do something like this (idx increments itself):
<?php $idx = 1;?>
<a href="file2.php?id=<?php echo $idx++;?>">page 1</a>
<a href="file3.php?id=<?php echo $idx++;?>">page 2</a>
<a href="file1.php?id=<?php echo $idx++;?>">page 3</a>
Or if you know what they are at this point, it doesn't have to be dynamic:
<a href="file2.php?id=1">page 1</a>
<a href="file3.php?id=2">page 2</a>
<a href="file1.php?id=3">page 3</a>
then within each of the files, you can retrieve its current page number:
<?php
$mynumber = $_GET['id'];
?>
.
.
<h1>Welcome to Page <?php echo $mynumber;?></h1>
Is that close?
$num = 0;
echo $num;
echo $num++;
echo $num;
Another one:
$num = $num += 1 is not needed. Use either $num += 1 or $num = $num + 1 or ofcourse $num++ or ++$num.