PHP rand( ) function

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   PHP rand( ) function
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
I'm trying to create a block of php that displays random images. so far i have:
<?php
                        echo rand(   );
            ?>


Now i found out that you can only have integers in the rand( ) function, so is there another peice of code i need to put URl's in the function?


Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
That rand function is used more or less with a query. Is this image information stored in a database?




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: PHP rand( ) function
wolf
CZ Active Member
usa.gif indiana.gif
Occupation: Student; Flash, HTML, PHP developer
Age: 34
Gender: Male
Status: Offline
Joined: Jul 25, 2003
0.02 posts per day
Posts: 168
Points: 10,417
AIM Address Yahoo Messenger MSN Messenger 
I did a search on the net about it and found a code that works, with this code im storing the images in an array, from outside sources...such as URL's. But yea, i did find a working code.



Back to top Reply with quote
#4   
aUsTiN
CZ Active Member
usa.gif georgia.gif
Age: 41
Gender: Male
Website:
Status: Offline
Joined: Sep 09, 2003
0.02 posts per day
Posts: 142
Points: 57
  MSN Messenger 
Just a quick FYI


   $bg = 1;
   $bg_dir    = 'PATH_TO_IMAGES';
   $bg_count    = opendir($bg_dir);      
      while ($file = readdir($bg_count))
         {         
         if (($file != ".") && ($file != "..") && ($file != "index.htm"))
            {
               $bg++;   
            }   
         }
         
   $random_bkg = rand ( 1, $bg );

   $bg_dir_c    = 'PATH_TO_IMAGES';
   $bg_file_c   = opendir($bg_dir);   
      while ($file2 = readdir($bg_file_c))
         {         
         $new_file    = explode(".", $file2);
         $check_file = $new_file[0];   
         }


Something like that would have got you a random image, $check_file being the filename...


Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum