所以,我的情况如下。我有比萨饼有价格,用户可以选择披萨应该有的尺寸(第1页)。当用户选择提交的尺寸(以及披萨的名称)时,在下一页上,用户可以根据尺寸选择浇头#。 2表示小型,3表示大型等(第2页)。由于用户可以但不一定必须选择最大量的浇头,因此我在保持数据分开方面存在问题。
我基本上想要区分为每个披萨选择的配料。目前我得到array(1) { ["toppings"]=> array(5) { [0]=> string(3) "Egg" [1]=> string(6) "Rucola" [2]=> string(6) "Rucola" [3]=> string(5) "Bacon" [4]=> string(10) "Mozzarella" } }
我想要一个包含披萨名称,大小,topping1,topping2,topping3,下一个披萨,大小,topping1,topping2,topping3的字符串。
由于
public function arrayIterator($pizzen) {
$html_table = "";
foreach($pizzen as $key) {
$html_table .= '<tr>';
foreach ($key as $value) {
if(is_numeric($value)) {
$html_table .= '<td>' . sprintf('%01.2f', $value) . '</td>';
} else {
$html_table .= '<td>' . $value . '</td>';
$checkboxValue = $value;
}
}
$html_table .= '<td><select class="selectpicker" name="size[]"><option></option><option name="small" value="' . $checkboxValue . ' small">Small</option>
<option name="large" value="' . $checkboxValue . ' large">Large</option><option name="xl" value="' . $checkboxValue . ' xl">X-Large</option>
</select></td><td><label class="form-check-label">
<input type="checkbox" name="ticked[]" value="' . $checkboxValue . '" /></input>
<input type="hidden" name="submitted" value="submitted-1"></td></tr>';
}
return $html_table;
}
/*
* printOrderDetails()
* toppingIterator()
* belong to page 2 of order process.
*
*
*/
public function toppingIterator()
{
if (($_POST['submitted']) && (count($_POST['ticked']) != null)) {
$mais = new Toppings(0.50, "Mais");
$kaese = new Toppings(1.00, "Cheese");
$ei = new Toppings(0.50, "Egg");
$rucola = new Toppings(1.00, "Rucola");
$bacon = new Toppings(1.50, "Bacon");
$schinken = new Toppings(1.50, "Bacon2");
$tuna = new Toppings(2.00, "Tuna");
$knofi = new Toppings(0.80, "Garlic");
$jalapenos = new Toppings(1.00, "Jalapenos");
$mozzarella = new Toppings(1.00, "Mozzarella");
$toppings = array($mais, $kaese, $ei, $rucola, $bacon, $schinken, $tuna, $knofi, $jalapenos, $mozzarella);
$toppingPrice = 0;
$maxOptions = 2; // least amount of toppings possible
$toppingTable = "";
foreach($_POST['size'] as $key => $sizes) {
echo $sizes . "<br/>";
if(strpos($sizes, "small") != 0) {
$maxOptions = 2;
} else if (strpos($sizes, "large") != 0) {
$maxOptions = 3;
} else if (strpos($sizes, "xl")) {
$maxOptions = 5;
}
if(!empty($sizes)) {
$toppingTable .= '<th>' . $sizes . '</th><td><select class="selectpicker" name="toppings[]" data-max-options="'
. $maxOptions . '" multiple>';
foreach ($toppings as $key) {
foreach ($key as $value) {
if (is_numeric($value)) {
$toppingPrice = sprintf('%01.2f', $value);
} else {
$toppingTable .= '<option name="'
. $value . '" value="' . $value . '">'
. $value . '(+' . $toppingPrice . 'EUR)' . '</option>';
}
}
}
$toppingTable .= '</select></td>';
} else {
}
}
echo('<form action="bestellen3.php" method="post" class="form-horizontal"><table class="table table-responsive table-bordered">
<thead>
<tr>
<th>Toppings</th>
</tr>
</thead>
<tbody>' . $toppingTable .
'</tbody></table><button type="submit" class="btn btn-primary">Abschicken</button></form>');
}
}