0

Hi,

I have created a mysql database containing menu dishes for a restaurant.

The idea is to store all dishes on the database whether the dish is being sold or has been sold in the past. Each dish (database row) has a simple indicator (yes/no) to determine if the row should be displayed for the current menu.

My issue is that when the chef wants to change the menu they will have to change the indicator on the stored row from off to on and vice versa.

To help with this I have built a simple query and form to present the data to the chef, however the form is mainly constructed of PHP variables resulting from the query.

i.e.

$query = "SELECT * FROM menu";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
		$id = $row['id'];
		$type = $row['type'];
		$item = $row['item'];
		$description = $row['description'];
		$price = $row['price'];
		$addmenu = $row['addmenu'];
		$string = 'yes';

if (strstr($addmenu,$string)) {
echo "<tr><td>".$id."</td><td>".$type."</td><td>".$item."</td><td>".$description."</td><td>".$price."</td><td><input type=checkbox  checked=checked name=".$id."</td></tr>";
}
else
{
echo "<tr><td>".$id."</td><td>".$type."</td><td>".$item."</td><td>".$description."</td><td>".$price."</td><td><input type=checkbox name=".$id."</td></tr>";
}}

This outputs a nice display showing the status of each database row.

my intention is for the chef to change the value of the checkboxes and repost the form so I can update the database with some very simple sql.

However, as each checkbox name is a php variable, I do not know how to pass the real value to process.

Also, I cannot predetermine the checkbox name as the user can add new rows to the database as chef creates new dishes.

Lastly, if it is possible to pass the php variable as a value for processing, i'm guessing I will have to create some sort of loop to identify each instance of of the variable/value.

Thanks for your time.

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by Thorby68
0

for each through the $_POST $_GET $_REQUEST arrays (however the form is sent)

the form will have valid name=>value pairs in its submitted data, that will match rows in the database, regardless of how they are generated

<?php
echo "<tr><td>".$id."</td><td>".$type."</td>
<td>".$item."</td><td>".$description."</td>
<td>".$price."</td>
<td><input type=checkbox name=".$id." value='serving'></td></tr>";
/* when processing form input
update table set serving="" */
foreach ( $_POST as $menuitem => $serving ) {/* do something with the sql table, 
probably/possibly 
update table set set serving='serving' where menuitem=$menuitem
Menu print is select * where serving='serving' (everything in the submitted form unchecked boxes dont submit) 
print this select on a menu */ }
?>

then future printings will be as the chef set, till the chef changes it again

Edited by almostbob: n/a

0

Almost form values are passed as variable with the name of your element and as almost said you can pick up that in another page using $_POST or $_GET.

0

Many thanks,

This is a fantastic function and so easy to work with.

Apart from the PHP manual (which I find a little difficult as I do not understand all of the terminology), can you suggest any good reading for PHP. I really think it's worth me investing in a good reference book.

Again many thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.