Grabbing prev next records

Discussion in 'Programming' started by spiney, Jul 25, 2006.

  1. #1
    I have 4 variables and I want to grab records from different parts of my database

    This is what I have
    $toprev = $row{'title'};
    $tofirst = $row{'title'};
    $tonext = $row{'title'};
    $tolast = $row{'title'};

    This is what I need (pseudo code):

    $toprev = $row{'title'} of prev record;
    /*so whenever I echo it, it should show the previous record in the db
    echo "$toprev";
    $tofirst = $row{'title'} of first record in the db;
    /*""
    $tonext = $row{'title'} of next record;
    /*""
    $tolast = $row{'title'} of last record in the db;
    /*""
    I know this isn't where you would put the code, it would probably be in the mysql_fetch_array part(I think).

    I have search to my wits end. Any help would be greatly appreciated!!!
     
    spiney, Jul 25, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    have a sql call to pull the three records you need, then right after you call the select, create a 2-dim array from your recordset, and close the DB connection.

    Now you can just get your items via index like $rows[0][1]; $rows[1][1]; and $rows[2][1];
     
    ccoonen, Jul 25, 2006 IP
  3. spiney

    spiney Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, just what I needed!
     
    spiney, Jul 26, 2006 IP