Random Image display

liunx

Guest
Hi Guys,<br /><br />Im doing this site at the moment <!-- m --><a class="postlink" href="http://www.skullduggeri.co.uk/">http://www.skullduggeri.co.uk/</a><!-- m --> <br />Im currently using Fireworks to do the graphics as was wondering if there is a way to make the image change each time the page is reloaded. (e.g the picture of the model centered would be different><img src='http://www.webdesignerforum.co.uk/style_images/1/post_snapback.gif' alt='*' border='0' /></div><div class='quotemain'><!--quotec-->something like this in your head:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /> define("randImg", rand(1,10) );?><!--c2--></div><!--ec2--><br /><br />and then to display the random image: (HTML, cut and paste)<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><img src=http://www.webdesignerforum.co.uk/lofiversion/index.php/'./images/image<?=RANDIMG;?>.jpg' alt="Image" /><!--c2--></div><!--ec2--><br /><br />assuming you have images located in an "images" folder, named image1.jpg, image2.jpg etc.<!--QuoteEnd--></div><!--QuoteEEnd--><br />This wont work as the constant isn't declared as case insensitive. Either the constant needs to match lower and upper cases, or declared case insensitive.<br /><br />For some reason I'd always though that the value you assigned to a constant had to be a fixed value, not an expression. Maybe I confused it with some other language.<!--content-->
constants are defined as case insensitive as default.<br /><br />Also, the return from rand() is a float/integer (a scalar value)<!--content-->
Accoring to the PHP5 manual constants are by default defined case-sensitive:<br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->The default behaviour is case-sensitive; i.e. CONSTANT and Constant represent different values.<!--QuoteEnd--></div><!--QuoteEEnd--><br />Maybe that's wrong, or it's changed. Not the first time...<!--content-->
might be a setting in my INI, might be a PHP4 relic, maybe I'm just wrong?<!--content-->
I dunno... the PHP docs has never been 100%. I did a quick test on my PHP4/5 installation and both threw an Notice. Both said they assumed the correct constant though. So if your error reporting isn't E_ALL | E_STRICT you won't see any complaints from PHP and it'd recover.<!--content-->
yaaay... we are both right ... its nice when that kind of thing happens...<!--content-->
 
Back
Top