SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Montgomery, TX
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Viewing Photos - Prev/Next, etc.

    Hello all,

    I've got a mySQL table for photos that users upload. The table contains the location of the photo and a description. I want to show 3 photos per page and use prev/next links. I'm getting all the photos with:

    PHP Code:
      $photos mysql_query("SELECT * FROM photos"); 
    Then, I want to loop through, using the correct index/spot in the array, so I'm doing this:

    PHP Code:
      //no direction first time you view the page.
      
    if ($direction == "")
        {
        
    $direction "next";
        
    $lastcnt 0;
        }

      
    $cnt $lastcnt;
      if (
    $direction == "next")
        {
        while ((
    $cnt <= $photo_count) && ($cnt <= ($lastcnt 3)))
          { 
          
    $photo $photos[$cnt];
          
    //html img tag here.....
          
    $cnt++;
          } 
        }
      else 
      if (
    $direction == "prev")
        {
        while ((
    $cnt >= 0) && ($cnt <= ($lastcnt 3)))
          {
          
    $photo mysql_fetch_array($photos[$cnt], MYSQL_ASSOC);
          
    //html image tag here.....
          
    $cnt--;
          }
         } 
    I've tried accessing the correct item in the photos array with the two ways in the while loops, but neither is working. Please point me in the right direction.

    Thanks,

    David

  2. #2
    SitePoint Enthusiast webmasts's Avatar
    Join Date
    Apr 2003
    Location
    usa
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to look at pagination:
    http://www.phpfreaks.com/tutorials/43/0.php

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin's tutorial on Paging Result Sets is definitely worth a look at:
    http://www.sitepoint.com/article/662


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
  •