ironman32 Posted March 25, 2009 Share Posted March 25, 2009 I have the idea of having data from an array list being chosen at random an input into table. The problem is that I'm not sure if this is possible . The idea is that the user clicks on a link and when they are taken to the page they will be shown data at random. Here is the page where the link resides. <html> <body> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="3"><strong>In which area do you wish to increase your muscle?</strong></td> </tr> <tr> <td width="100"><a href="uppergen.php">Upper</a> </tr> </td> <tr> <td width="100">Lower body </td> </tr> <tr> <td width="100">Total body (Combination of upper and lower body) </td> </tr> </td> </body> <html> And this is the page it links to with the array list <?php $shoulder_array = array(); $shoulder_array[0] = "<a href=\"http://www.muscleandstrength.com/exercises/military-press.html\">Military press (Barbell)</a>"; $shoulder_array[1] = "<a href=\"http://www.muscleandstrength.com/exercises/military-press.html\">Military press</a>"; $shoulder_array[2] = "<a href=\"http://www.muscleandstrength.com/exercises/military-press.html\">Military press</a>"; $shoulder_array[3] = "<a href=\"http://www.muscleandstrength.com/exercises/military-press.html\">Military press</a>"; ?> <html> <body> A minimum rest period of one day is required between each workout day. <table border="1"> <tr><td rowspan="2">Day 1</td> <td>Stretch/Warm up </td><td><?php echo $shoulder_array[0]; ?></td> <td><?php echo $shoulder_array[2]; ?></td><td> <td><?php echo $shoulder_array[3]; ?></td><td> <td><?php echo $shoulder_array[3]; ?></td> </tr> </table> <p></p> <table border="1"> <tr><td rowspan="2">Day 2</td> <td>Stretch/Warm up </td><td><?php echo $shoulder_array[0]; ?></td> </tr> </table> </body> </html> The idea is to have the data put in at random. Any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/151074-solved-random-output-from-an-array-list/ Share on other sites More sharing options...
POG1 Posted March 25, 2009 Share Posted March 25, 2009 $count = count($shoulder_array); echo $shoulder_array[mt_rand(0,$count)]; Link to comment https://forums.phpfreaks.com/topic/151074-solved-random-output-from-an-array-list/#findComment-793657 Share on other sites More sharing options...
Mark Baker Posted March 25, 2009 Share Posted March 25, 2009 shuffle($shoulder_array); echo $shoulder_array[0]; Link to comment https://forums.phpfreaks.com/topic/151074-solved-random-output-from-an-array-list/#findComment-793677 Share on other sites More sharing options...
ironman32 Posted March 25, 2009 Author Share Posted March 25, 2009 Thanks for the help Link to comment https://forums.phpfreaks.com/topic/151074-solved-random-output-from-an-array-list/#findComment-793725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.