snow
Members-
Posts
18 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
snow's Achievements
Newbie (1/5)
0
Reputation
-
An updateable shopping cart, using PHP sessions to store the cart.
snow replied to snow's topic in PHP Coding Help
that looks very good, however I need to store data in php not through a database. but thanks i'll look into it. please any more suggestions are welcome. -
Hi guys, I'm new at PHP, and currently for university I am undertaking a project with the objective to create "An updateable shopping cart, using PHP sessions to store the cart." Obviously this is too much for anyone to just 'help' me do, so I was wondering whether anyone here could suggest a helpful guide that would help me to understand how to create this. Any help would be much appreciated, thanks in advance. Edit: and yes sorry I forgot to mention I have been looking around on google but haven't found anything really helpful!
-
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!
-
this almost worked. however every price value is $1.00, makes no sense! thanks heaps for help
-
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.
-
Please any help would be great... :'(
-
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!
-
Hi sorry for another topic, just in dire help. Here is my array stored in menu_data.php: <?php $days = array(); function myarray() { global $days; $days = array ( "Monday"=>array ( "Chicken Burger", "Veal Schnitzel", "Onion Rings", "Hot Potato" ), "Tuesday"=>array ( "Steak Sandwich", "Chicken Pasta", "Pork Chop", "Taco" ), "Wednesday"=>array ( "Chicken and Chips", "Beef Casserole", "Pasta", "Lasagne" ), "Thursday"=>array ( "Fish and Chips", "Tuna Pattie", "Chicko Roll", "Hot Dog" ), "Friday"=>array ( "Nachos", "Tuna Pattie", "Maccaroni Cheese", "Bacon and Eggs" ) ); } ?> and I use this array to print a menu from it on print_menu.php: <?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) { echo "<li>" . $meal . "</li>"; } echo "</ul></li>"; } ?> This is for a university assignment, now all of a sudden they've gone: So basically I need to print out a menu, that displays the day, then under that, the menu for that day as well as how much each order costs. I am really confused working with more then 2 arrays in one. Can anyone please help in doing this. Thank you very much.
-
Oh I got it working, thank you very much!
-
Thank you. But does this work for forms? Should I do this on the post page of the form: $_SESSION['day'] = $_POST['day']; $_SESSION['time'] = $_POST['time']; $_SESSION['delivery'] = $_POST['delivery'];
-
Hi can someone simply explain how I can use hidden form elements so I can keep variables for later on. For example: Web Page 1 (Has the forms) --> Web Page 2 (gets $_POST) --> Web Page 3 now has lost all the post data from page 2, how do I keep it so I can re-use it? I'm new at php and any help would be appreciated, preferrably simple methods! Thanks heaps in advance!
-
Need help with including a function please! New at php (Uni assignment)
snow replied to snow's topic in PHP Coding Help
And your last response, sorry, is what I need to do after the stuff I posted above! -
Need help with including a function please! New at php (Uni assignment)
snow replied to snow's topic in PHP Coding Help
This is the part I'm currently working on taken from my assignment, this is obviously the best way I can explain what I need to do to you: -
Need help with including a function please! New at php (Uni assignment)
snow replied to snow's topic in PHP Coding Help
Ok I'll print out everything I have: menu-data.php (functions): <?php function my_array() { $days = array ( "Monday"=>array ( "Chicken Burger", "Veal Schnitzel", "Onion Rings", "Hot Potato" ), "Tuesday"=>array ( "Steak Sandwich", "Chicken Pasta", "Pork Chops", "Taco's" ), "Wednesday"=>array ( "Chicken and Chips", "Beef Casserole", "Meatballs", "Lasagne" ), "Thursday"=>array ( "Fish and Chips", "Tuna Pattie", "Chicko Roll", "Hot Dog" ), "Friday"=>array ( "Nachos", "Tuna Patties", "Maccaroni Cheese", "Bacon and Eggs" ) ); $return implode(",", $myarray); } ?> enter.php (the form): <?php include_once("menu-data.php"); $array = my_array(); $days = $array[0]; // 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 />"; } ?> This doesn't work, and what further complicates things is that I need another page that again uses the array stored in the menu-data.php from before but prints everything out like this: <?php echo "<h1><u>Menu</u></h1>"; foreach ($days as $day => $meals) { echo "<li><b>" . $day . "</b><ul>"; foreach ($meals as $meal) { echo "<li>" . $meal . "</li>"; } echo "</ul></li>"; } ?> This prints out: - Day - Meal 1 - Meal 2 etc... -
Need help with including a function please! New at php (Uni assignment)
snow replied to snow's topic in PHP Coding Help
Hmm... see that doesn't work because my next line of code in using your example "show-it.php" is: foreach ($days as $day => $meals) { echo "<input type=\"radio\" name=\"day\" value=\"" . $day . "\">" . $day; echo "<br />"; } Which loops through my multidimensional array and spits out a radio button for each main day, so people can choose which day they want to dine.