Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using 'if' for Next Page in site 1

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
0
0
With Back and Next at the bottom of 9 webpages, I would like to be able to say s o m e t h i n g like

if($id == '1'){
<a href="../parents/sip2.php>{

if($id == '2'){
<a href="../parents/sip3.php>}

... and that sort of thing for the 9 pages.

Then I would like to do the same for Back (But I should be able to do that alright if some kind Expert will help this struggler.)

Thanks in advance, Gurus.
 
Braces back to front on line 3, sorry.
 
Very sorry, Vragabond.
(The FAQ page seems no longer available, unfortunately.)

My question is how to code to change to the next page, (or back to the previous page) on a website.

In essence, if this page is id=1 then the Next page you want is id=2, and if this page is id=2 then you want page id=3 Next.

I wonder if there is a way to code that, and if so, a hint about the way the code should go, please?
 
The FAQ is very much available to me, I don't know what problems you seem to be having. We know nothing of how you are displaying your results, so I will assume that if you provide the correct $id, the results adjust accordingly. So, what you want to do (very simply) is this:
Code:
e.g. results.php file

// code to display results based on $_GET['id']
...

// display buttons for next and previous
   $next = $_GET['id'] + 1;
   $previous = $_GET['id'] - 1;

   echo '<a href="?id=' . $previous . '">Previous</a> | ';
   echo '<a href="?id=' . $next . '">Next</a>';
Add some error checking and that is basically it.
 
Hi Vragabond,
I tried all ways to get to the FAQs, even going to the index page and trying to get there by adding the id for that question. Must be our timeouts here, sorry.

Thanks very much for the code.

Vragabond, do I not have to define in some way which of the Next pages is Next?

It looks really excellent, thank you.
 
Brilliant, Vragabond! Works a real treat. (PHP has to be close to magic.) Appreciated very much, thank you.
 
Vragabond, could I ask you how to set the limit to the number of pages, the limit of the IDs, please?
 
Hmmm, without knowing how exactly it all works, I can only suggest a simple solution:
Code:
   $total = 10;

   if ($previous > 0) 
   { 
      echo '<a href="?id=' . $previous . '">Previous</a> | ';
   }
   if ($next <= $total)
   {
      echo '<a href="?id=' . $next . '">Next</a>';
   }
I guess you can fill the $total variable with the number you need.
 
Cheers, Vragabond, many thanks.
 
That works really very well, Vragabond. Very much obliged to you. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top