Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Append number to multiple lines of html text


  • Please log in to reply
6 replies to this topic

#1 Chip Smith

Chip Smith

  • Members
  • 27 posts
  • OFFLINE
  •  
  • Local time:12:24 AM

Posted 30 October 2009 - 02:49 PM

odd question, but is there a way to add (or generate) a number to lines of html?

example:

First line:
<a href="images/gallery/big/tat1.jpg" rel="lightbox[tats]"><img src="images/gallery/thumbnail/tat1.jpg" alt="" /></a>

then the next line would be:
<a href="images/gallery/big/tat2.jpg" rel="lightbox[tats]"><img src="images/gallery/thumbnail/tat2.jpg" alt="" /></a>

just the numbers oh each pic are changing. I have 200+ pics that need to be displayed and i don't want to have to go thru each one and change the number, if there's any easier way of generating it.

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:24 AM

Posted 30 October 2009 - 03:17 PM

Sure. A simple PHP loop can do it. Something like:
for ( $1 = 0; $1 < 100; $1 += 1) {
   echo('<a href="images/gallery/big/tat' . $i .'.jpg" rel="lightbox[tats]"><img src="images/gallery/thumbnail/tat1.jpg" alt="" /></a>');
}

A simple Javascript loop can do the same:
for (i = 0; i < 100; i+=1){
	  document.write('<a href="images/gallery/big/tat' + i +'.jpg" rel="lightbox[tats]"><img src="images/gallery/thumbnail/tat1.jpg" alt="" /></a>');
}

The code is untested, but demonstrates how to do trivial loops.

#3 Chip Smith

Chip Smith
  • Topic Starter

  • Members
  • 27 posts
  • OFFLINE
  •  
  • Local time:12:24 AM

Posted 30 October 2009 - 03:43 PM

I know very little about php and java scripting....would i need anything special the run those loops?

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:24 AM

Posted 30 October 2009 - 03:45 PM

You don't need anything special to use Javascript, other than time researching how to properly use it. Use of PHP requires that the server be running PHP.

#5 Chip Smith

Chip Smith
  • Topic Starter

  • Members
  • 27 posts
  • OFFLINE
  •  
  • Local time:12:24 AM

Posted 30 October 2009 - 03:52 PM

wow, that was really simple....got it to work on the first try :thumbsup:

thanks so much!

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:24 AM

Posted 30 October 2009 - 04:18 PM

Srsly? Cool!

#7 Chip Smith

Chip Smith
  • Topic Starter

  • Members
  • 27 posts
  • OFFLINE
  •  
  • Local time:12:24 AM

Posted 30 October 2009 - 05:26 PM

yeppers, just adjusted your code ever so slightly

[codebox]<script type="text/javascript">
var i=1;
for (i = 1; i < 100; i+=1){
document.write('<a href="images/gallery/big/tat' + i +'.jpg" rel="lightbox[tats]"><img src="images/gallery/thumbnail/tat' + i +'.jpg" /></a>');
}
</script> [/codebox]

and it worked right out of the gates, including all the lightbox stuff....fast and simple, wham, bam, thank you ma'am...er, sir

Edited by Chip Smith, 30 October 2009 - 05:39 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users