SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb How to create dynamic "next" link in PHP

    Hi, guys.

    Here is the problem I have ran into - I need to create the "next" and "previous" links on the site that has bunch of images.
    I can not have MySQL DB or any DB for that matter as the hosing provider does not support DBs. I need to create the page that would a template that gets filled with six images and provides dynamic links "back" and "next". Once a user clicks "next" the template page is filled with six more images and "next" link(button) points to the next page that would be filed with six more images.

    Any ideas how to do it? Sample code would be really appreciated. The only language hosting provider supports is PHP and it runs on IRIX.

    Thanks guys

  2. #2
    SitePoint Zealot
    Join Date
    May 2002
    Location
    RI-USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Might want to post this in the php section of the forums. I used Kevin Yank's example in the article over at http://www.webmasterbase.com/article/662

    Seems to be what your looking for

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Maybe I don't understand but looks like it is more of DB related version. I don't have that option unfortunatly....
    Any other ideas

  5. #5
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks. But forum would that be?

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    SitePoint Zealot p2ranger's Avatar
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a sript I used for scrolling through some of my pictures on my site. It doesn't offer any thumbs, but I'm sure that if you tinker with it you can do that.

    It has been along time since I fiddled with it so I'll try to comment on it (I forgot to add comments when I wrote it)

    It realied on one file called 2001.php which is what I called this script you are looking at. I had 3 sets of pictures and named all 3 sets of pictures with prefixes to id that set of pictures. eg. ca01.jpg, 2001summer01.jpg, aa01.jpg

    All the pictures resided in the same directory as this script

    The first page it generated allowed for the selection of what set of pictures you wanted to look at. Once you selected the set of pictures, it went to the first one in that set eg. ca01.jpg It then generated links for next and previous. I used a simple counter $num++ or $num-- depending on which direction was chosen. eg. while showing ca01.jpg and if next is chosen, $num++ would alter the img src tag pointing to ca02.jpg This relies on having your pictres named with a convention though.

    As it got to the last picture in the order (which I knew ahead of time and give a value to) it would return to the selection screen for the picture sets.

    Hope this gives you something to build off of.

    Jason
    ><>

    PHP Code:

    <html>
    <head>
           <title>2001 Pictures</title>
    </head>
    <body>

    <?php

    $hit_max
    =0;
    if (!isset(
    $set))
    {
            echo
    '<p><a href="2001.php?direction=next&set=2001summer">2001 Summer</a></p>';
            echo
    '<p><a href="2001.php?direction=next&set=aa">2001 Autumn Adventure</a></p>';
            echo
    '<p><a href="2001.php?direction=next&set=ca">2001 California</a></p>';
            

    }
    else
    {
         if (!isset(
    $num))  {
                    
    $num=1;
         }

         elseif (@
    $direction == "next")  {
                            
    $num++;
          }

         elseif(@
    $direction == "prev")   {
                            
    $num--;
          }

         if (@
    $set == "2001summer")  {

            echo
    '<title>2001 Summer Pictures</title>';
            if (@
    $num 35)  {
                    echo
    '<p>End of Summer 2001 picture set</p>';
                    
    $hit_max=1;
            }
            elseif (@
    $num 1) {
                    
    $num=35;
            }
         }

         elseif (@
    $set == "aa")  {
            echo
    '<title>2001 Autumn Adventure</title>';
            if (@
    $num 33)  {
                    echo
    '<p>End of Autumn Adventure 2001 picture set</p>';
                    
    $hit_max=1;
            }
            elseif (@
    $num <1) {
                    
    $num=33;
            }
         }

         elseif (@
    $set == "ca") {
            echo
    '<title>2001 California</title>';

            if (@
    $num 18)  {
                    echo
    '<p>End of California 2001 picture set</p>';
                    
    $hit_max=1;
            }
            elseif (@
    $num <1)  {
                    
    $num=18;
            }
         }



          echo
    '<p><a href="2001.php">Return</a> to 2001 pictures home</p>';
          if  (!@
    $hit_max) {
                echo
    '<p><a href="2001.php?direction=next&set='.$set.'&num='.$num.'">Next</a></p>';
                echo
    '<p><a href="2001.php?direction=prev&set='.$set.'&num='.$num.'">Previous</a></p>';
          }
          
    $picname sprintf("%s%02d.jpg",$set,$num);
          echo
    '<p><img src="'.$picname.'"></p>';
    }



    ?>
    </body>
    </html>
    Last edited by p2ranger; Sep 20, 2002 at 09:51.

  8. #8
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you, Jason. Let's see what will come out of it. Check out www.a1trade.com in few weeks. Maybe you'll even like something over there


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
  •