Array selecting

Discussion in 'PHP' started by dmanto2two, Mar 24, 2010.

  1. #1
    I'd like to query my database and ask it for an array of photo ids belonging to a user and order it by time desc. Then from that array i would like to select the photo one up or one down from the current photo. i was thinking i could then search the array by the value after the => select the number in the []. i tried attaching a photo but i'm not sure if it uploaded.
    Anyway what i want to do is create a url with id of the next photo and one with the previous photo id in it, so i can have next and previous buttons for my photos.
     

    Attached Files:

    dmanto2two, Mar 24, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Have you any code? Write here and say what doesn't work in the code.
     
    s_ruben, Mar 24, 2010 IP
  3. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #3
    A sloppy (and slow) solution, can't think of a better way atm
    
    $currentpic = ??;
    $number = -1;
    for($k = 0; $k < count($array); $k++)
    {
    if($array[$k] == $currentpic)
    {
    $number = $k;
    break;
    }
    }
    if($number == -1)
    {
    echo 'image 404';
    }
    
    PHP:
     
    pig2cat, Mar 25, 2010 IP
  4. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You sure, your code like that?
    I do not understand what is mean
     
    waterbomm, Mar 25, 2010 IP