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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post

    Next and Previous ID's from a table

    I need to get the previous and next ID's from a table. The table has a group that they are in as well. I have the following code, but it will only pull the ID of the current page.

    PHP Code:
     $sqlnext mysql_query ("SELECT * FROM tutorials WHERE id > '$id' AND series='$series' ORDER BY id LIMIT 1");
     
    $rownext mysql_fetch_array ($sqlnext);
     
    $nextid $row['id'];
     
    $nextname $row['name'];
     if((!empty(
    $nextid)) && ($nextid != $id))
     {
       
    $next="<a href=\"./$basepage?page=tutorials&command=view&id=$nextid\">$nextname</a>";
     } 
    I can offer more code if needed.
    Last edited by Sandcrawler; 03-01-2010 at 04:12 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    $nextid = $row['id']+1;

    Try that?

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    No, because it won't work the way I need it to.

    The table will have multiple groups or series. SO id+1 is likely to be in a different series, or hidden.

  • #4
    New Coder
    Join Date
    Sep 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    I found what was wrong... just a typo. I forgot to change it to $nextid = $rownext['id']; causing it to use the prior query instead.


  •  

    Posting Permissions

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