Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts

    PHP Dynamic link for next button

    Hi There, I am trying to figure out how to link my photos so that the entire photo can be used as a next button. Currently, the page id controls which image is viewed. I need this new link to basically echo the current id + 1...
    In other words if ?id=A1 I would like the link to bring up ?id=A2.

    <a href="adventure.php?id=<?php echo $id; ?>">

    How can I adjust the syntax to make that happen. How do I limit it at ?id=A26 andhave this link go back to ?id=A1?

    Thanks,
    Rich V

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    PHP Code:
    $id=$_GET["id"];
    preg_match('{(\d+)}'$id$m);
    $id $m[1];
    $id+=1;$id="A$id";if($id=="A27"){$id="A1";} 
    Is there any reason you need the "A" in it? Or did you want it to go to B at some point? It doesn't seem to be doing anything so, you could easily use just a number and eliminate the need for a regular expression to extract the number. Then it would be as simple as:

    PHP Code:
    $id=$_GET["id"];$id+=1;if($id=="27"){$id="1";} 

  • Users who have thanked binaryWeapon for this post:

    reach100 (08-12-2008)

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks...
    That worked great...
    Rich
    Last edited by reach100; 08-12-2008 at 02:01 AM.

  • #4
    New Coder
    Join Date
    May 2008
    Posts
    36
    Thanks
    6
    Thanked 0 Times in 0 Posts
    How can I get it to skip id?=A15?
    Thanks for your help...
    Rich V

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    PHP Code:
    $id=$_GET["id"];
    preg_match('{(\d+)}'$id$m);
    $id $m[1];
    $id+=1;$id="A$id";if($id=="A27"){$id="A1";}
    if(
    $id=="A15"){$id="A16";} 
    Glad to help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •