Log in

View Full Version : Auto numbering?



bruglione
11-14-2008, 11:14 AM
~~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

jc_gmk
11-14-2008, 04:36 PM
You will need to use a "while" loop for this.
Can be done client-side or server side:

JavaScript solution:


<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
$i=1;
while($i<=350)
{
echo '<a href="images/photo (' . $i . ').jpg"></a><br />';
$i++;
}
?>

bruglione
11-17-2008, 08:33 AM
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?

jc_gmk
11-17-2008, 09:11 AM
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 />

bruglione
11-17-2008, 09:14 AM
Alright, I'll check it out right away when i get home.

Thanks a lot, problem solved