snow Posted September 12, 2007 Share Posted September 12, 2007 Hey sorry I don't really know how to explain this but I will try most simply and best. Here is the problem: I have this array: $days = array ( "Monday"=>array ( "Chicken Burger"=>array("$5.00"), "Veal Schnitzel"=>array("$7.50"), "Onion Rings"=>array("$3.00"), "Hot Potato"=>array("$4.00") ), "Tuesday"=>array ( "Steak Sandwich"=>array("$10.00"), "Chicken Pasta"=>array("$4.50"), "Pork Chop"=>array("$6.50"), "Taco"=>array("$1.50") ), "Wednesday"=>array ( "Chicken and Chips"=>array("$5.00"), "Beef Casserole"=>array("$6.50"), "Sausage"=>array("$1.50"), "Lasagne"=>array("$3.50") ), "Thursday"=>array ( "Fish and Chips"=>array("$5.00"), "Tuna Pattie"=>array("$2.50"), "Chicko Roll"=>array("$2.80"), "Hot Dog"=>array("$3.00") ), "Friday"=>array ( "Nachos"=>array("$5.50"), "Salad Sandwich"=>array("$4.00"), "Macaroni Cheese"=>array("$3.50"), "Bacon and Eggs"=>array("$7.50") ) ); The user then selects their day, it then goes to another page and prints out all the menu for that DAY in the form of radio buttons. I had this working, UNTIL, I had to add another array for prices. The previous code worked like this: echo "<h3>Please select your meal for " . $_SESSION['day'] . ":</h3>"; $day = $_SESSION['day']; $dayMenu = $days[$day]; foreach ($dayMenu as $item): echo "<input type=\"radio\" name=\"meal\" value=\"" . $item . "\">" . $item . "<br />"; endforeach; Can anyone tell me the code which will print out all the menu and prices for a day a user selects, you can use the example above and modify it I would think would be easiest. Thanks very much. EDIT: I realised i haven't made much sense. I will need a series of radio buttons like this for example: Monday o Chicken Burger - $5.00 o Veal Schnitzel - $7.50 o Onion Rings - $3.00 o Hot Potato - $4.00 where o = a radio button! Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/ Share on other sites More sharing options...
snow Posted September 12, 2007 Author Share Posted September 12, 2007 Please any help would be great... :'( Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347105 Share on other sites More sharing options...
wildteen88 Posted September 12, 2007 Share Posted September 12, 2007 Example: <?php $days = array( 'Monday' => array( 'Chicken Burger' => 5.00, 'Veal Schnitzel' => 7.50, 'Onion Rings' => 3.00, 'Hot Potato' => 4.00 ), 'Tuesday' => array( 'Steak Sandwich' => 10.00, 'Chicken Pasta' => 4.50, 'Pork Chop' => 6.50, 'Taco' => 1.50, ), 'Wednesday' => array( 'Chicken and Chips' => 5.00, 'Beef Casserole' => 6.50, 'Sausage' => 1.50, 'Lasagne' => 3.50 ), 'Thursday' => array( 'Fish and Chips' => 5.00, 'Tuna Pattie' => 2.50, 'Chicko Roll' => 2.80, 'Hot Dog' => 3.00 ), 'Friday' => array( 'Nachos' => 5.50, 'Salad Sandwich' => 4.00, 'Macaroni Cheese' => 3.50, 'Bacon and Eggs' => 7.50 ) ); if(isset($_GET['day']) && array_key_exists($_GET['day'], $days)) { echo '<h3>Please select your meal for ' . $_GET['day'] . ':</h3>'; $day = $_GET['day']; $dayMenu = $days[$day]; foreach ($dayMenu as $item => $price) { $price = number_format($price, 2); echo '<input type="radio" name="meal" value="' . $item . '">' . $item . ' ($' . $price . ")<br />\n "; } } else { echo '<h1>Please select day:</h1> <form action="#" action="get"> '; foreach($days as $day => $menu) { echo '<input type="radio" name="day" value="' . $day . '"> ' . $day . "<br />\n "; } echo '<input type="submit" value="Submit"> </form>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347172 Share on other sites More sharing options...
snow Posted September 13, 2007 Author Share Posted September 13, 2007 this almost worked. however every price value is $1.00, makes no sense! thanks heaps for help Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347545 Share on other sites More sharing options...
snow Posted September 13, 2007 Author Share Posted September 13, 2007 Can someone please expand on wildteen88's post, fixing it so it doesn't only produce $1.00 values for each meal. This is due in 30 minutes! Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347572 Share on other sites More sharing options...
Barand Posted September 13, 2007 Share Posted September 13, 2007 I don't know what you've done to WT's code but it gives me [pre] Please select your meal for Monday: ( ) Chicken Burger ($5.00) ( ) Veal Schnitzel ($7.50) ( ) Onion Rings ($3.00) ( ) Hot Potato ($4.00) Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347629 Share on other sites More sharing options...
wildteen88 Posted September 13, 2007 Share Posted September 13, 2007 I have changed your format of the days variable. Notice I have changed it so the price is not an array within the days variable, as you are only storing 1 piece of information for each food item. Make sure you are using the days variable in my code within your code. Sorry I forgot to mention that earlier. Quote Link to comment https://forums.phpfreaks.com/topic/69054-another-array-problem/#findComment-347844 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.