Click to See Complete Forum and Search --> : [RESOLVED] how do i replace loaded picture with new rand picture on page


notsleepy
10-15-2006, 07:17 PM
hi, newbie so be gentle!
searching through the post here, i think this seems the nearest to what i'm after! anyone reading it for the first time will see it's connection!! and rather than starting a new thread i thought it might nest comfortably together, forgive me if this is not the done thing. - at least it's not off topic!!

i have an html form, when it is returned to and/or refreshed i want a new picture to load
__________________

how do i swap this

<html>
<p><img border="0" src= "../folder1/folder2/Picture75.JPG" width="30" height="40"></p>
</html>

for something like this

<?php
{
$randpicture = rand(10,99)
$newpicture = "../folder1/folder2/Picture".$randpicture.".JPG"
}
?>


<html>
<p><img border="0" src= $newpicture width="30" height="40"></p>
</html>

i've tried saving the page as .php then inserting <?php and ?> either side of the string $newpicture, tried blocking the html bits to with ...><?php $newpicture ?><... and various other logical and perhaps not so logical arrangements but it still doesn't bring up a picture!! even tried various arrangements of brackets and/or quotes/apostrophes all to no avail :mad:

i'm asuming the rand(10,99) is correct, ramdom number between 10 and 99 ??

the red bits are the bits i'm trying to swap, ie static string for random string.

i've asked over on the html board (not in this much type) but as there have been no responses at all at all i thought i'd give it a go here too!
__________________

i would like it to initially happen without a mouseclick on a button. then perhaps mouseover the page to refresh when returning with the 'back button'

it's driving me nuts!! as a VB6 person i know it should be possible, but then code is code and unless it's correct......!

webnerd612
10-16-2006, 08:33 AM
Save the file with a .php extension (provided that's what your web server is set up to recognize php scripts by) then use the following example:

<html>
<p><img border="0" src="<?= $newpicture ?>" width="30" height="40"></p>
</html>

The <?= expands the variable within the HTML. Other wise, you would have to say: <? echo($newpicture); ?>, alt: <?php echo($newpicture); ?>

If you're comming from VB 6, make sure your php code lines end with semi-colons. I noticed your code example did not.

notsleepy
10-16-2006, 10:02 AM
webnerd612 is a star !! :) :)
works like a treat!
it was that second equals sign that got me! i would never have guessed!

re semi-colons, yep! the other one that's bugging me is the no endif but { and } instead, much harder to see if they're missing!! It took a while to realise they were important! and suddenly it dawned, like a tonne of bricks!! Breakthrough though, i'll forget the time wasted now and push on to discover i still don't know alot about php!!! :confused:

I have time though, which is my saviour!

i'll get the habit i'm sure, ;)

cheers again = : )

webnerd612
10-16-2006, 10:32 AM
I'm happy that I could help.

May I suggest that O'Reilly and Apress both publish several good books on php programming and there are many good tutorials available on the web.

Glad to have you among the ranks. I hope your learning experience is a pleasant one.