Results 1 to 5 of 5

Thread: Auto numbering?

  1. #1
    Join Date
    Nov 2008
    Location
    The Netherlands
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post

    Exclamation Auto numbering?

    ~~RESOLVED~~



    Alright you've probably all had this problem:

    I have 350 pictures wich i want to play in my lightbox gallery.
    The code for each picture looks like this:

    <a href="images/photo (1).jpg" rel="lightbox[example]" title="photo 1"><img src="images/photo (1).jpg" height="80" width="80"></a>


    In my folders i have my pictures called photo (1), photo (2) till photo (350).
    Is there any script that will copy the code above 350 times and automaticly numbers them from (1) to (350)?

    Thanks,
    Bruglione
    Last edited by bruglione; 11-19-2008 at 08:11 AM.

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    You will need to use a "while" loop for this.
    Can be done client-side or server side:

    JavaScript solution:

    HTML Code:
    <script type="text/javascript">
    var i=0;
    while (i<=350)
    {
    document.write('<a href="images/photo (' + i + ').jpg"></a>');
    document.write("<br />");
    i=i+1;
    }
    </script>
    PHP solution:

    PHP Code:
    <?php 
    $i
    =1;
    while(
    $i<=350)
      {
      echo 
    '<a href="images/photo (' $i .  ').jpg"></a><br />';
      
    $i++;
      }
    ?>

  3. The Following User Says Thank You to jc_gmk For This Useful Post:

    bruglione (11-17-2008)

  4. #3
    Join Date
    Nov 2008
    Location
    The Netherlands
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Thanks a lot but one more question...

    How would the PHP code look when I add more links (photo's)?

    Or do i only have to add this one, and it automaticly creates all 350 links?

  5. #4
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    PHP runs server-side and outputs html to the browser.
    So yes, it will create all the links automatically, e.g.

    <a href="images/photo (1).jpg"></a><br />
    <a href="images/photo (2).jpg"></a><br />
    <a href="im...
    <a href="images/photo (349).jpg"></a><br />
    <a href="images/photo (350).jpg"></a><br />

  6. #5
    Join Date
    Nov 2008
    Location
    The Netherlands
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Alright, I'll check it out right away when i get home.

    Thanks a lot, problem solved

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
  •