|  | Posted by Geoff Berrow on 03/03/07 10:21 
Message-ID: <fjohu29bo3enigbupm4npjmino161i2g86@4ax.com> from FredAtkinson contained the following:
 
 >	I'll look your coding over.  Maybe I can figure it out well
 >enough to code it into my page.  .
 
 If the data is structured in an organised way it will be easier to
 extract in the way you want (even if that way is random).
 
 Getting a random number $z (let's not get into a discussion about true
 randomness kiddies) is easy.  Say you wanted a random number between $x
 and $y.  You just do $z=rand($x,$y);
 
 Now you can see that if images are coded with a sequential number as the
 name it would be easy to do
 
 <img src="image<?php echo $z;?> alt="">
 
 However, chances are they won't be.  Arrays however, can have numeric
 keys.
 
 So if you have an array like this
 
 $array[]=cat.jpg;
 $array[]=dog.jpg;
 $array[]=fish.jpg;
 $array[]=goat.jpg;
 
 PHP will assign numeric keys to the array, starting at zero
 
 The number of keys is derived from count($array).  So the last key is
 Applying that to the above we get
 
 $z=rand(0,(count($array)-1));
 (aside - I know about shuffle folks - this is easier to explain)
 
 and you output it like this
 <img src="image<?php echo $array[$z];?> alt="">
 
 
 Now your only problem is getting the contents of a given directory into
 an array.  For this you have to loop through the contents of a directory
 to find all the image files and assign them to the array.
 
 See my gallery script for an idea of how this is done
 www.walkingoutdoors.co.uk/Geoff/gallery/gallery.zip
 
 example:
 http://www.walkingoutdoors.co.uk/Geoff/tryfan/
 
 --
 Geoff Berrow  0110001001101100010000000110
 001101101011011001000110111101100111001011
 100110001101101111001011100111010101101011
  Navigation: [Reply to this message] |