snow Posted September 13, 2007 Share Posted September 13, 2007 Hi php freaks! My problem is I have this array here in menu-data.php: <?php $days = array(); function myarray() { global $days; $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") ) ); } ?> I then use this array to print out a menu in another web page called "print-menu.php" in the form of: Day 1: Meal 1 - Price Meal 2 - Price Meal 3 - Price etc.... Using this code: <?php include("menu-data.php"); myarray(); // Print menu. echo "<h1><u>Menu</u></h1>"; foreach ($days as $day => $meals) { echo "<li><b>" . $day . "</b><ul>"; foreach ($meals as $meal => $costs) { echo "<li>" . $meal . " "; foreach ($costs as $cost) { echo "- " . $cost . "</li>"; } } echo "</ul></li>"; } ?> <a href="enter.php">Place an order!</a> enter.php then brings up a series of radio buttons assigned to the values of the DAYS in the array. e.g. o Monday o Tuesday etc... Using this code: <?php session_start(); include("menu-data.php"); myarray(); echo "Please select the day you would like to eat:<br /><br />"; // Loop through and display each day as a radio button. foreach ($days as $day => $meals) { echo "<input type=\"radio\" name=\"day\" value=\"" . $day . "\">" . $day; echo "<br />"; } ?> They then pick their day they want to eat, now what I want to know is how I can use the day they choose, so when they submit it, the next page (select_meal.php) prints out just the menu for that day from the original array in the form of radio buttons, eg say they choose monday it will display: 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. I had this working with the array using the following code, however it now doesn't work anymore since I added prices to my array: <form action="order.php" method="post"> <?php session_start(); include("menu-data.php"); myarray(); $_SESSION['day'] = $_POST['day']; $_SESSION['time'] = $_POST['time']; $_SESSION['delivery'] = $_POST['delivery']; 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 />"; // outputs "Chicken Burger endforeach; echo "<br />"; ?> <input type="submit" value="Place order!" /> I know this must be alot to take in but I really need help it's summative and due very soon! If I haven't made much sense please tell me. Thanks everyone in advance. Quote Link to comment https://forums.phpfreaks.com/topic/69138-need-help-turning-contents-of-an-array-into-a-radio-button-form/ Share on other sites More sharing options...
Kurrel Posted September 13, 2007 Share Posted September 13, 2007 At first glance, it appears you need to precede the dollar symbol with a \. I think what's happening is that it's seeing that price as a newly declared PHP variable without any data in it. Quote Link to comment https://forums.phpfreaks.com/topic/69138-need-help-turning-contents-of-an-array-into-a-radio-button-form/#findComment-347612 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.