friendlylad Posted February 1, 2007 Share Posted February 1, 2007 I am trying to use "array_rand to make 3 random photos out of a total of 9 photos show up on a webpage...one photo on the top left side one in very center, and the other on the bottom right of window with text besides it. I have written the following code, but do not know why the images are not showing up and what i need to add to make the photos show up in that layout I have a directory of images (that contains all my files) and the actual file is on the outside of that directory on a server. I also need to be able to click on the photo and it should take me to that photo in another page.... If you anyone can help me or can give me so websites to visit that are helpful i would really apreciate it. If you want you can email me the code too....sedricbenson@hotmail.com. I need to get this done before midnight tonight. Thanks Heres the code: <html> <head> <title>Benson's Cafe</title> </head> <body> <center> <h1>Benson's Cafe</h1> <table width = '100%'> <tr> <?php $food = array ( "cookies"=>"cookies.jpg", "khmer1"=>"khmer1.jpg", "khmer2"=>"khmer2.jpg", "khmer3"=>"khmer3,jpg", "khmer4"=>"khmer4.jpg", "khmer5"=>"khmer5.jpg", "khmer6"=>"khmer6.jpg", "salad"=>"salad.jpg", "lemonpie"=>"lemonpie.jpg"); // Create array of 3 randomly selected KEYS from the original array $randKeys = array_rand($food, 3); // Print the array of the randomly selected KEYS print "<br><br>"; print_r($randKeys); print "<br><br>"; for ( $i = 0; $i < 3; $i++ ) { echo '<img src="images/' . $food["cookies"] . '">'; } print "<br><br>"; ?> </tr> </table> <body> </html> Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 How do i change this code to work with 3 images on a page with text besides them using the array rand function in PHP??? I really need some help. Thanks <?php $pictures = array('tire.jpg', 'oil.jpg', 'spark_plug.jpg', 'door.jpg', 'steering_wheel.jpg', 'thermostat.jpg', 'wiper_blade.jpg', 'gasket.jpg', 'brake_pad.jpg'); srand ((float)microtime()*1000000); shuffle($pictures); ?> <html> <head> <title>Bob's Auto Parts</title> </head> <body> <center> <h1>Bob's Auto Parts</h1> <table width = 100%> <tr> <?php for ( $i = 0; $i < 3; $i++ ) { echo '<td align="center"><img src="'; echo $pictures[$i]; echo '"width="100" height="100"></td>'; } ?> </tr> </table> </center> </body> </html> Quote Link to comment Share on other sites More sharing options...
trq Posted February 1, 2007 Share Posted February 1, 2007 Sorry... what is the question? Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 my coding is off in that right now, i would like to display 3 random images on a webpage with text beside them i also need to be able to click on a photo and go to a separate webpage or link of just that file is there any way you can tell me what i need to do with my code to make it do this?? thanks Basically, i am trying to modify the second program on this page to work with array rand and make 3 images get randomly selected and placed on a webpage with descriptive text besides it....anyone good enough with php? Thanks for your help Quote Link to comment Share on other sites More sharing options...
trq Posted February 1, 2007 Share Posted February 1, 2007 That code pretty much does just that. Where do you want this text to come from? Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 i don't want text, i just want to make sure the program on top of this page works correctly with php and that it will place 3 random images on a web page with text by the photos Quote Link to comment Share on other sites More sharing options...
trq Posted February 1, 2007 Share Posted February 1, 2007 i would like to display 3 random images on a webpage with text beside them You don't want text? Which is it? Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 ok sorry for the confusion, let me try and simplify it: //i would like a webpage that looks like the following [] will have to = an image: Benson's Cafe [] random image 1 with a description text beside it [] random image 1 with a description text beside it [] random image 1 with a description text beside it // THIS IS ALL TO BE DONE WITH array rand instead of $shuffle....because $shuffle cannot include text Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 does that make sense?? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 Try this: (change it to fit your code.) $pictures = array(); $pictures[] = array('image.jpg'=>'description'); $pictures[] = array('image2.jpg'=>'description2'); $pictures[] = array('image3.jpg'=>'description3'); $pictures[] = array('image4.jpg'=>'description4'); $pictures[] = array('image5.jpg'=>'description5'); shuffle($pictures); for($i=0; $i<3; $i++){ print_r($pictures[$i]); } Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 if i were to do that....what would be left in the actual coding?? would this work??? <html> <head> <title>Benson's Cafe</title> </head> <body> <center> <h1>Benson's Cafe</h1> <table width = '100%'> <tr> <?php print "Three reasons why you must come to the Benson's Cafe"; $food = array(); $food[] = array('images/cookies.jpg'=>'We make the best cookies'; $food[] = array('images/khmer1.jpg'=>'We create the best dishes'); $food[] = array('images/khmer2.jpg'=>'We have the best variety'); $food[] = array('images/khmer3.jpg'=>'We can keep you full'); $food[] = array('images/khmer4.jpg'=>'We can make you come back'); $food[] = array('images/khmer5.jpg'=>'We can keep you entertained'); $food[] = array('images/khmer6.jpg'=>'We are always there for you'); $food[] = array('images/salad.jpg'=>'When you are hungry we will feed you'); $food[] = array('images/lemonpie.jpg'=>'You will never walk away hungry'); shuffle($food); for($i=0; $i<3; $i++){ print_r($food[$i]); } for ( $i = 0; $i < 3; $i++ ) { echo '<img src="images/' . $food["cookies"] . '">'; } print "<br><br>"; ?> </tr> </table> <body> </html> Quote Link to comment Share on other sites More sharing options...
friendlylad Posted February 1, 2007 Author Share Posted February 1, 2007 yeah even when i do that i don't get any images or text to show up on the webpage... uhhh this has taken me like 6 hrs already today.... lol Quote Link to comment Share on other sites More sharing options...
trq Posted February 1, 2007 Share Posted February 1, 2007 uhhh this has taken me like 6 hrs already today.... lol Yeah... it helps if you at least have a basic understanding of what the code does. Where here to help not do. Change this.... echo '<img src="images/' . $food["cookies"] . '">'; to.... echo '<img src="images/' . $food[$i][0] . '">'.$food[1]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.