You are here: Re: inserting random photo with caption « HTML « IT news, forums, messages
Re: inserting random photo with caption

Posted by Jonathan N. Little on 12/31/05 19:31

carolyn wrote:
> Els wrote:
>
>
>>carolyn wrote:
>>
>>
>>>I am looking for a script that can load a random photo or other graphic
>>>into
>>>a web page. The trick is that I would also like it to load a related
>>>caption with the image.
>>>
>>>I have found lots of scripts that will load random photos, and also ones
>>>that will load random text. I have not found any that can load text
>>>related to a random photo. I may have to hone my programming skills and
>>>merge some scripts to do what I would like, however I am hoping that
>>>someone already has done the work and is making it available to the
>>>world.
>>>
>>>Thanks for pointing me in the right direction!
>>
>>I'd say take the script that does the random text, and just add some
>>text like "<img src="..." alt="..."> to it?
>>
>
>
> Thanks! I think I must have been asleep for the past few days. I kept on
> thinking about taking the graphic scripts and wondering how to add the
> text. Taking the text and adding the graphic looks very simple.
> Apparently too simple for me to come up with on my own. LOL
>
Seems like everyone may be missing what Carolyn is asking, if you want
associated text with image that randomly selected, what you need is some
sort of database. You do not need a real database a flat file table
would do. How you implement it depends on whether client-side JavaScript:
function Snapshot(src,text){
this.src=src;
this.text=text;
}

var snapshots=new Array;
var i=0;
snapshots[i++]=new Snapshot('someImg.jpg','My text about some image.');
snapshots[i++]=new Snapshot('anotherImg.jpg','Text about another.');
....

make a random function that picks a number between 0 and
(snapshots.length-1)

then another function to write in associated image src and text

document.write('<img src="' + snapshots[randomNum].src + '">');
document.write('<p>' + snapshots[randomNum].text+ '</p>');


Perl, or PHP or other server-side scripting (which would be a far better
solution)

create a text flat-file database with text editor say, 'snapshot.txt':

#image field [tab separator] text field
someImg.jpg My text about some image.
anotherImg.jpg Text about another.
....

Have you script read the file 'snapshot.txt' into an array and like the
JavaScript pick a random number then build page or the results (Perl
show)...

my $lastRec = $#snapshots;
my $randomNum = RandomFunc($lastRec);
my ($imgSrc, $imgText) = split("\t", $snapshots[$randomNum]);

then build page as required...have fun!




--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация