need help here. im learning php and mysql. i am creating a system, with php and mysql. this is like a ordering system.
i have one table for ingredients from my database, two type of ingredients, meat and vegetables.
ingredient table looks like these:
| ingredientid | in_name | in_type | in_price |
below is my code to display list of ingredients with checkboxes, because i wanted the user to pick any ingredients he wanted to choose.
include ('dbconnect.php');
<form action="index.php" method="post">
<table>
<tbody>
<tr>
<th>Meat:</th>
<th>Vegetables:</th>
</tr>
<tr>
<td>
<?php
$meat =mysql_query("Select * FROM ingredients WHERE intype LIKE 'meat' ");
while ($row_meat = mysql_fetch_array($meat)) {
echo '<input type="checkbox" name="meat[]" value="'.$row_meat[3].'">'.$row_meat[1].'<br/>';
}
?>
</td>
<td>
<?php
$vegetable = mysql_query("Select * FROM ingredients WHERE intype LIKE 'vegetable'");
while ($row_veg = mysql_fetch_array($vegetable)) {
echo '<input type="checkbox" name="veg[]" value="'.$row_veg[3].'">'.$row_veg[1].'<br/>';
}
?>
</td>
</tbody>
</table>
<p>
<input type="submit" name="submit_order" value="Add to Order">
</p>
<form>
from the above code i am able to separate the two type of ingredients into two columns, namely meat and vegetables. letting the user to choose any ingredients he likes for his order and then submit it. when he submits his order, the name of the ingredients he choose and the price of the ingredients and the total of all the ingredients he choose will appear on the right side of the page.
so this is my second code
<div id="right">
<?php if (isset($_POST['submit_order'])) {
if (!empty($_POST['meat'])) {
echo '<h3>Meat:</h3><span class="right">';
foreach ($_POST['meat'] AS $key_meat => $element_meat) {
$meats = mysql_query("Select name FROM ingredients WHERE price ='".$element_meat."' ");
$row_meats = mysql_fetch_array($meats);
echo $row_meats[name].' - P'.$element_meat.'.00<br/>';
$total_meat += $element_meat;
}
echo '</span>';
}
if (!empty($_POST['veg'])) {
echo '<h3>Vegetables:</h3><span class="right">';
foreach ($_POST['veg'] AS $key_veg => $element_veg) {
$vegs = mysql_query("Select name FROM ingredients WHERE price ='".$element_veg."' ");
$row_vegs = mysql_fetch_array($vegs);
echo $row_vegs[name].' - P'.$element_veg.'.00<br/>';
$total_vegs += $element_veg;
}
}
echo '</span>';
}
?>
</div>
<div id="total">
<?php
$total1 = $total_meat+$total_vegs;
if (isset($_POST['submit_order']))
if (($total_meat+$total_vegs) != 0) {
echo 'P'.($total_meat+$total_vegs);
} ?>
</div>
</div>
what i want is when he submits his order, the choosen ingredients remains checked! and when he adds another ingredients and hit 'add to order' button again, the new ingredients he checked will be added to the right side along with the previous ingredients displayed on the right side. any idea please?

New Topic/Question
Reply



MultiQuote





|