Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8937263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:22:31+00:00 2026-06-15T10:22:31+00:00

I have a form for users to create a daily mealplan using recipes from

  • 0

I have a form for users to create a daily mealplan using recipes from our database. The processes are as follows:

1) An admin selects 2 recipes for each meal (Lunch and/or Dinner), for the desired date. These selections are what will be used to populate the customer meal select lists.

2) A customer selects 1 recipe for each meal available, for the desired date.

The PROBLEM:

The form only seems to be processing the values selected from the last list displayed on the page and I am not sure why.

Here’s the code sections I’ve been working with. (I can post more if necessary)

// 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&amp;dosql=update&amp;view=daily&amp;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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:22:32+00:00Added an answer on June 15, 2026 at 10:22 am

    The lunch and dinner code sections are using the same values for the name attributes. You need to give them different names altogether or append [] to create an array.

    EDIT: For example,

    echo '<input type="checkbox" name="delete_'.$i.'[]" value="yes"></td>';
    

    Notice the [] inside the double quotes for the value of the name attribute. You’d need to do this to all of them. I am not familiar with DBUtils::arrayselect so I am not if sure the following will work.

    echo DBUtils::arrayselect($mealList, 'meal_id_'.$i.'[]', 'size=1', $meal);
    

    But as long as you have more than one field with the same name, they will overwrite each other. With making these fields into arrays, you also need to change the code that processes the form so that it can process an array.

    EDIT: You could also increment $i between the lunch and dinner sections instead of creating an array. Incrementing $i within the loop would require changing the for parameters, but at least you wouldn’t have to change the code that processes the form.

    The for line seems very convoluted to me (and inefficient). A single line of code is not more efficient if it runs unnecessary calculations on each iteration of a loop. If I understand the intention correctly, try replacing the for line with the following.

    $maxshow = 1;
    $num_items = isset($MPObj->mealplanItems[$dbDate]) ? count($MPObj->mealplanItems[$dbDate]) : 0;
    if ($num_items + $minshow < $maxshow) $maxshow = $num_items + $minshow;
    $maxshow = $maxshow * 2; //double it because we will be incrementing $i within the loop
    
    for ($i = 0; $i < $maxshow; $i++) {
    

    And then add the following line between your original lunch and dinner sections (the ones without []).

    $i++;
    

    That effectively assigns different names to each field without creating arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an admin form that lets users create entities that require an image.
I have a form where users can create unlimited number of rows (using jquery-
I have a form where users can modify a collection of objects using a
I have a form where users create Person records. Each Person can have several
I'm trying to create a form where users can save their progress. I have
So I have a form that lets a user create a new team. Our
I have a form that lets users create new records, In the field that
Right now, I have two views that are using the users#create action: users/new.thml.erb and
I have a form which takes users information and stores it in the database.
I have a form where users submit different fields to create events. The number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.