-
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
-
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++;
}
?>
-
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?
-
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 />
-
Alright, I'll check it out right away when i get home.
Thanks a lot, problem solved