SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help w/gallery function - prev next links

    I'm working on a photo gallery which needs to allow the user to cycle through images like they are using the view photo feature in windows xp (as the client put it), so I need to setup some "previous" and "next" links.

    I've set something up at the moment but it doesn't take note of the photo categories because it is based on the photos id, not category.

    Does anybody know how I can go about setting this up so it sticks to the right category and still cycles through?

    I don't have access to the code on this machine (my other doesn't have internet access atm as the isp is down), so I'm sorry I can't post that here. All I can say is the link takes the id of the current photo and either adds one or subtracts one - I know this the wrong way to do it, but I can't seem to figure out exactly what is required. I really hope this post is making sense.

    Any help would be greatly appreciated!
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I'm assuming the data is stored in a databse since you talked about IDs and such.

    What you could do is run two querys like such...

    SELECT photoID FROM photos WHERE (photoID < $displayed_photo_ID) AND (photoCat = $displayed_photo_category) ORDER BY photoID DSC LIMIT 1;

    SELECT photoID FROM photos WHERE (photoID > $displayed_photo_ID) AND (photoCat = $displayed_photo_category) ORDER BY photoID DSC LIMIT 1;

  3. #3
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's what I did:

    (reminder: this was pulled straight out of an old project I did...change the query's and table name's accordingly, but keep the same ORDER's etc...)

    PHP Code:
    function prev_next$pr,$nx )
    {
        
    $nav '<a href="'.$self.'?pg_cat='.$_GET['pg_cat'].'&amp;photo='.$pr.'">&laquo; Previous</a>';
        
    $nav .= ' | ';
        
    $nav .= '<a href="'.$self.'?pg_cat='.$_GET['pg_cat'].'&amp;photo='.$nx.'">Next &raquo;</a>';
        return 
    $nav;
    }


    $photo_prev_q tep_db_query("SELECT m_id
    FROM multimedia 
    WHERE m_cat_id='
    $pgcat
    AND m_type = 'Photo Gallery' 
    AND m_id < '
    $photoid
    AND m_status = 1 
    ORDER BY m_id DESC 
    LIMIT 1"
    );

    $photo_next_q tep_db_query("SELECT m_id
    FROM multimedia 
    WHERE m_cat_id='
    $pgcat
    AND m_type = 'Photo Gallery' 
    AND m_id > '
    $photoid
    AND m_status = 1 
    ORDER BY m_id ASC 
    LIMIT 1 "
    );

        
    // Grab Previous and Next ID's 
        
    while ( $photo_prev_r tep_db_fetch_array($photo_prev_q) )
        {
        
    $prev $photo_prev_r['m_id'];
        }
        while ( 
    $photo_next_r tep_db_fetch_array($photo_next_q) )
        {
        
    $next $photo_next_r['m_id'];
        }
        if ( (
    $prev == '') && ($next == '') ) // don't go anywhere
        
    {
        
    $prev $_GET['photo'];
        
    $next $_GET['photo'];
        }
        elseif ( 
    $prev == '' // loop to the last
        
    {
        
    $photo_prev_alt_q tep_db_query("SELECT m_id
        FROM multimedia 
        WHERE m_cat_id='
    $pgcat
        AND m_type = 'Photo Gallery' 
        AND m_status = 1 
        ORDER BY m_id DESC 
        LIMIT 1"
    );
            while ( 
    $photo_prev_alt_r tep_db_fetch_array($photo_prev_alt_q) )
            {
            
    $prev $photo_prev_alt_r['m_id'];
            }
        }
        elseif ( 
    $next == '' // loop to the first
        
    {
        
        
    $photo_next_alt_q tep_db_query("SELECT m_id
        FROM multimedia 
        WHERE m_cat_id='
    $pgcat
        AND m_type = 'Photo Gallery' 
        AND m_status = 1 
        ORDER BY m_id ASC 
        LIMIT 1"
    );
        
            while ( 
    $photo_next_alt_r tep_db_fetch_array($photo_next_alt_q) )
            {
            
    $next $photo_next_alt_r['m_id'];
            }
        }
        
    // run our nifty function
        
    $prev_next prev_next($prev,$next); 

  4. #4
    SitePoint Evangelist Alexandra's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Australia
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. Sorry I should have mentioned I was using a database, good one for picking that up!

    I'll try out what you've suggested and let you know if I have any problems. Thanks again!
    Alex Graham
    Cadmium Design & Development
    www.cadmium.com.au
    alexandra@cadmium.com.au

  5. #5
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh yea, don't forget to echo $prev_next
    but honestly, I know there is probably some nifty PEAR library function that can spit this out nice and easy, but I wouldn't have a clue.
    The above code takes into consideration the possibilities of having only 1 photo or more.
    Also, it loops thru back to the beginning once you've reached the end...and visa-versa.


Bookmarks

Posting Permissions

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