Forum Moderators: coopster

Message Too Old, No Replies

sending page info from one page to the next

         

mschultem

2:47 pm on Mar 10, 2007 (gmt 0)

10+ Year Member



hi,
i would like to ask for guidance on the following problem.

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

cameraman

5:57 pm on Mar 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you give us a little more information? What determines the page's number - its position in a list of links? From your text I'm inferring that the file "file1.php" in the first order, #1, is the same physical "file1.php" that's #3 in the second order - is that correct? So file1.php needs to know at any given time what its page number is for this particular display opportunity?

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?

mschultem

1:35 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



hi,
thanks for your reply.
i need a dynamic solution so i tried your first suggestion.
unfortunately the $id++ does not increase the value -> for testing i just use:

$num=0;
echo $num;
echo $num++;

for both i get '0' back.

thanks
m

mschultem

1:41 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



hmm - it seems that $num=$num+=1; works.
does this make sense or is it awfully ugly?
greets
m

adb64

1:53 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



If you do this:

$num = 0;
echo $num;
echo $num++;
echo $num;

the last one will print 1. The $num++ will first return the current value of $num and after that it will increment $num. If you want to increment before, use ++$num;

Another one:
$num = $num += 1 is not needed. Use either $num += 1 or $num = $num + 1 or ofcourse $num++ or ++$num.

mschultem

10:38 am on Mar 16, 2007 (gmt 0)

10+ Year Member



thanks!
that solved the problem
m