-
Hello :rolleyes:
Anyone would have an idea how to change a table content (few lines of text plus one graphic) every time the page is visited? I wanted visitors to be welcome each time they come back to home page by a different message and a different picture.
Thank you very much
-
make the welcome message from javascript then create random script.
Use the same script i showed you last time but just adapt it a bit so it displays text and not just a picture
http://www.java-scripts.net/javascri...e-Script.phtml
-
You can use PHP.
Your webpage would have the extension .php (index.php instead of index.html).
Then, with PHP, you would read a text file that has a whole list of your images
and a comment for each image.
The PHP script could read a line randomly, or sequentially, or by date, etc.
Changing with each page refresh, or with each day ...
See this example of images changing randomly with each page refresh:
http://www.pierreandclaudia.com
Let us know how you want the content to change, and if you can/or will
change your page extension to .php (index.php).
Also, create a text file (using Notepad) that looks something like this:
Caption and photo separated by "pipes" |
Our place of business|our_company.jpg|
Employee Photo|emp_photo.jpg|
Another Caption Here|photo123.jpg|
.
.
.
-
Hello
Thank you for your answer.
Unfortunately the script from http://www.java-scripts.net/javascri...e-Script.phtml will work only with pictures (the command is “random_imglink”).
Mlseim please tell me how could I manage to do this effect with PHP? Is there any copy&past PHP script I could use? Is it a problem if my home page is in PHP and all others in html?
-
Only the page that is using PHP to display the image needs to be .php
How do you want the pictures to change?
With each refresh,
change each day,
?
-
Hi Mlseim,
I would like to change picture and few lines of the text, every time the page is reloaded.
Thanks a lot
-
Try making the following changes to that link that was posted by Perad (changes in red)...
Code:
<script language="JavaScript">
<!--
/*
Random Image Link Script
By Website Abstraction (http://www.wsabstract.com)
and Java-scripts.net (http://www.java-scripts.net)
*/
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="img1.gif"
myimages[2]="img2.gif"
myimages[3]="img3.gif"
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.wsabstract.com"
imagelinks[2]="http://www.dynamicdrive.com"
imagelinks[3]="http://www.java-scripts.net"
var captions = new Array()
captions[1] = "Javascript is cool";
captions[2] = "PHP is cooler";
captions[3] = "but Raspberryh is the coolest";
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>' + captions[ry])
}
random_imglink()
//-->
</script>
Or even BETTER, have a div for your caption, and do:
Code:
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
document.getElementById("caption").innerHTML = captions[ry];
...(and just make sure you include
into your div tag)
OR if you don't want a particular caption to be associated with an image (in other words, you want the caption to be random AND the image to be random SEPARATELY), then generate two different random numbers for each one, like this:
Code:
var ry=Math.floor(Math.random()*myimages.length)
var rz=Math.floor(Math.random()*captions.length)
if (ry==0)
ry=1
if (rz==0)
rz=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
document.getElementById("caption").innerHTML = captions[rz];
Heather
-
OK,
So you have your text file like this (saved as "photos.txt" ):
Our place of business|our_company.jpg|
Employee Photo|emp_photo.jpg|
Another Caption Here|photo123.jpg|
Then, you need to put this PHP script at the very
top of your web page (index.php):
<?php
$pickline = file("photos.txt");
shuffle($pickline);
list ($caption, $photo) = split ('\|', $pickline[0]);
?>
Then, wherever you need the photo and caption do this:
(however you have your <table> or <div> ) ....
<table>
<tr><td><img src="<?=$photo?>"><br><?=$caption?></td></tr>
</table>
-
Hello
Thank you everyone for helping.
Melseim I tried your suggestion, I hoped that was the simplest one. But couldn’t edit it on the web site (netdirms are not supporting php) :-(
Then I turned to Raspberryh’s solution, but it is not working either.
Could you please have a look at the code?
http://www.sample332uk-00027-hp.com/index.html
-
That's a bummer!
I suggest you do this:
Go to this webhost: http://www.cleverdot.com
and purchase the $29.99 plan for an ad-free site WITH your own domain name!
That's really cheap. You can hardly NOT take an offer like that.
They offer everything you need (PHP, MySQL, etc.)
I've also used Netfirms, and although they are good, Cleverdot is cheaper and I've
never had any problems with them either.
============
You must use PHP, not just for solving your problem, but for future dynamic
page generation, content management and other powerful things.
Spend the money and have fun playing around ... you won't regret it!