BleepingComputer.com: Append number to multiple lines of html text

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.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Append number to multiple lines of html text

#1 User is offline   Chip Smith 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 27
  • Joined: 29-September 09

  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.

#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   Chip Smith 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 27
  • Joined: 29-September 09

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#5 User is offline   Chip Smith 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 27
  • Joined: 29-September 09

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 30 October 2009 - 04:18 PM

Srsly? Cool!
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#7 User is offline   Chip Smith 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 27
  • Joined: 29-September 09

Posted 30 October 2009 - 05:26 PM

yeppers, just adjusted your code ever so slightly

<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> 


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

This post has been edited by Chip Smith: 30 October 2009 - 05:39 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users