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 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Next-Previous function needs help

    This Next | Previous function works well, but for the last page, I need to link back to the start.

    I’m trying to say in this code that if the end is reached – id 45 – then return to the start page. But it doesn’t want to work like this. Advice would be appreciated, experts.

    $next = $_GET['id'] + 1;
    $previous = $_GET['id'] - 1;
    $total = 45;

    if ($previous > -1)
    {
    echo '<p><a href="?id=' . $previous . '">Previous</a> | ';
    }
    if ($next <= $total)
    {
    echo '<a href="?id=' . $next . '">Next</a><br>';
    }

    if(!$id > 44)
    { echo '<a href="Thoughts.php" Title="Back to the Philosophy titles."> Back to the start</a>'
    }
    ?>

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Do you have a link where we can see this working?
    What is happening?

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .

    $next = $_GET['id'] + 1;
    $previous = $_GET['id'] - 1;
    $total = 45;

    if ($previous >= 0)
    {
    echo '<p><a href=\"thispage.php?id=$previous\">Previous</a> | ';
    }
    if ($next <= $total)
    {
    echo '<a href="\"thispage.php?id=$next\">Next</a><br>';
    }

    if($id > 44)
    { echo '<a href="Thoughts.php" Title="Back to the Philosophy titles."> Back to the start</a>'
    }
    ?>

    Hope it helps.

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks macmonkey and NancyJ.

    macmonkey, it doesn't want to work out, not even when I state the last id and say if it equals that number, show this page.

    I'll have to have more of a fiddle later.

    Good to hear from you NancyJ. Unfortunately, the pages aren't on a server yet. I think part of the trouble would be solved if I could renumber the records in chronological order. But I don't think that's possible - or if it is, be very pleased to hear how.

    Cheers, Experts.

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Shouldnt this:
    Code:
     if(!$id > 44)
    { echo '<a href="Thoughts.php" Title="Back to the Philosophy titles."> Back to the start</a>'
    }
    be
    Code:
     if($id > 44)
    { echo '<a href="Thoughts.php" Title="Back to the Philosophy titles."> Back to the start</a>'
    }
    If I'm understanding you correctly you want to show the 'Back to Start' link when $id is greater than 44 (ie when its 45) but your code says show the link when $id is NOT greater than 44...
    is this what is happening?

    If this isnt what is wrong it would be helpful for you to tell us what exactly is happening, since we cant experience it for ourselves we have to rely on you to describe the problem... just saying it doesnt work like you want isnt enough information

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dear NancyJ

    Thanks very much. Of course, and such a simple error. Thank you very much for finding it, and telling me. Insanity averted, thank you.

  • #7
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hey zonkd

    since I can't see your full query I'll do an example of how I'd do it. It may be 1/2 assed but works for me:

    PHP Code:
    <?
    include('includes/db_connect.php'); // connect to mysql db

    $result mysql_query("SELECT * FROM stories");
    while(
    $myrow mysql_fetch_assoc($result)) {
    $next $myrow['id'] + 1;
    $previous $myrow['id'] - 1;
    $total 45;

    if (
    $previous >= 0) {
       echo 
    "<p><a href=\"thispage.php?id=$previous\">Previous</a> | ";
       }
    if (
    $next <= $total)
    {
    echo 
    "<a href=\"thispage.php?id=$next\">Next</a><br>";
    }

    if(
    $id 44)
    { echo 
    "<a href=\"Thoughts.php\" Title=\"Back to the Philosophy titles.\"> Back to the start</a>";
    }
    }
    ?>
    Last edited by macmonkey; 09-21-2005 at 03:26 PM.


  •  

    Posting Permissions

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