我有一个表格供用户使用我们数据库中的食谱创建每日膳食计划。流程如下:
1) 管理员为所需日期的每餐(午餐和/或晚餐)选择 2 个食谱。这些选择将用于填充客户膳食选择列表。
2) 客户为所需日期的每餐选择 1 个食谱。
问题:
该表单似乎只处理从页面上显示的最后一个列表中选择的值,我不知道为什么。
这是我一直在使用的代码部分。(有需要我可以发更多)
// Create a new Meal Plan object
$MPObj = new MealPlan($date);
$MPObj->load($dbDate,$dbDate); // Just want this one day
$minshow = 1;
$defaultServings = 1;
// Read in a list of Meals and Recipes
$rc = DBUtils::fetchColumn( $db_table_meals, 'meal_name', 'meal_id', 'meal_id' );
$mealList = DBUtils::createList($rc, 'meal_id', 'meal_name');
array_unshift_assoc($mealList, 0, ""); // add an empty element to the list
--
$sql = "SELECT mplan_date,
mplan_recipe,
recipe_name,
meal_name,
recipe_serving_size
FROM recipe_mealplans
LEFT JOIN $db_table_meals ON meal_id = mplan_meal
LEFT JOIN $db_table_recipes ON recipe_id = mplan_recipe
WHERE mplan_date = '".mysql_real_escape_string($dbDate)."'
AND mplan_owner = '".mysql_real_escape_string($user_SK)."'
ORDER BY recipe_name";
$rc = $DB_LINK->Execute($sql);
DBUtils::checkResult($rc, NULL, NULL, $sql);
--
while (!$rc->EOF) {
if ($rc->fields['meal_name'] === "Lunch") {
$recipeListLunch[($rc->fields['mplan_recipe'])] = $rc->fields['recipe_name'] . " (" . $rc->fields['recipe_serving_size'] . ")";
}
if ($rc->fields['meal_name'] === "Dinner") {
$recipeListDinner[($rc->fields['mplan_recipe'])] = $rc->fields['recipe_name'] . " (" . $rc->fields['recipe_serving_size'] . ")";
}
$rc->MoveNext();
}
--
<form action="index.php?m=meals&dosql=update&view=daily&date=<?php echo $date; ?>" method="post" enctype="multipart/form-data">
<table cellspacing="1" cellpadding="4" border="0" width="80%" class="data">
<tr>
<th align="center">Remove</th>
<th align="center">Meal</th>
<th align="center">Servings</th>
<th align="center"></th>
<th align="center">Menu Options</th>
</tr>
<?php
// Print out all the existing meals, and some new ones
for ($i = 0, $maxshow = 1; $i < (isset($MPObj->mealplanItems[$dbDate]) && ($i < $maxshow) ? count($MPObj->mealplanItems[$dbDate]) : 0) + $minshow; $i++) {
if ($i < (isset($MPObj->mealplanItems[$dbDate]) ? count($MPObj->mealplanItems[$dbDate]) : 0)) {
// If it is an existing meal item, then set it
$meal = $MPObj->mealplanItems[$dbDate][$i]['meal'];
$servings = $MPObj->mealplanItems[$dbDate][$i]['servings'];
$recipe = $MPObj->mealplanItems[$dbDate][$i]['id'];
} else {
// It is a new one, give it blank values
$meal = NULL;
$servings = $defaultServings;
$recipe = NULL;
}
/* Display Meal Lists to select from */
// Lunch
echo '<tr>';
echo '<td align="center">';
echo '<input type="checkbox" name="delete_'.$i.'" value="yes"></td>';
echo '<td align="center">';
echo DBUtils::arrayselect($mealList, 'meal_id_'.$i, 'size=1', $meal);
echo '</td><td align="center">';
echo '<input type="text" autocomplete="off" name="servings_'.$i.'" value="' . $servings . '" size="3">';
echo '</td><td align="center">';
echo '<input type="hidden" autocomplete="off" name="repeat_'.$i.'" value="1" size="3"> ';
echo '</td><td align="center">';
echo DBUtils::arrayselect($recipeListLunch, 'recipe_id_'.$i, 'size=1', $recipe);
echo '</td></tr>';
// Dinner
echo '<tr>';
echo '<td align="center">';
echo '<input type="checkbox" name="delete_'.$i.'" value="yes"></td>';
echo '<td align="center">';
echo DBUtils::arrayselect($mealList, 'meal_id_'.$i, 'size=1', $meal);
echo '</td><td align="center">';
echo '<input type="text" autocomplete="off" name="servings_'.$i.'" value="' . $servings . '" size="3">';
echo '</td><td align="center">';
echo '<input type="hidden" autocomplete="off" name="repeat_'.$i.'" value="1" size="3"> ';
echo '</td><td align="center">';
echo DBUtils::arrayselect($recipeListDinner, 'recipe_id_'.$i, 'size=1', $recipe);
echo '</td></tr>';
} // end for
?>
</table>
<?php
if isset($recipeListLunch) || isset($recipeListDinner)) {
echo '<input type="submit" value="Update Menu" class="button">';
}
?>
</form>