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

  • Home
  • SEARCH
  • 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 6859409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:16:46+00:00 2026-05-27T02:16:46+00:00

I am trying to create a menu where users can view a menu that

  • 0

I am trying to create a menu where users can view a menu that they create. The menu consists of a dropdown box which the users use to filter the menu by week.

The menu then displays the seven days of the week and the five types of meal times their are which is breakfast, lunch, dinner, pudding and snack. Below is how i am currentley displaying it so far.

 $sqlmeasurement = mysql_query("SELECT title FROM recipe JOIN menu ON recipe.recipeid = menu.recipeid WHERE menu.weekid = '".$selectweek."' AND menu.mealtimeid = '1'") or die(mysql_error()); 
 Print '<table border="0">
    <tr>
      <th width="100"> </th>
      <th width="200">Monday</th>
    </tr>'; 
    echo "<tr>";
    echo "<td><strong>Breakfast</strong></td>";
    echo "<td>";
 while($info = mysql_fetch_array( $sqlmeasurement )) 
 { 
    echo $info['title']; 
   echo "<br/>";
 } 
 echo "</td> ";
 echo "</tr>"; 
 echo "</table>";

As you can see this PHP statement selects what i want from the table but because there are 7 days a week and 5 types of meal times this means that i will have to copy this code 35 times in order to display all that i want.

So for example the next bit of code will be like this:

 $sqlmeasurement2 = mysql_query("SELECT title FROM recipe JOIN menu ON recipe.recipeid = menu.recipeid WHERE menu.weekid = '".$selectweek."' AND menu.mealtimeid = '2'") or die(mysql_error()); 
 Print '<table border="0">';

    Print '<tr>
      <th width="100"> </th>
      <th width="200"> </th>
    </tr>';
    echo "<tr>";
    echo "<td><strong>Lunch</strong></td>";
    echo "<td>";
 while($info2 = mysql_fetch_array( $sqlmeasurement2 )) 
 { 
    echo $info2['title']; 
   echo "<br/>";
 } 
 echo "</td> ";
 echo "</tr>"; 
 echo "</table>";

And so on until i have all the days and their meal times.

Is there a way to display all the information without all this iteration?

  • 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-05-27T02:16:47+00:00Added an answer on May 27, 2026 at 2:16 am

    You have various options. You could put the output into a function, and just call that with varying parameters.

    function ouptutMeal($selectweek, $mealtime, $mealname) {
        $sqlmeasurement2 = mysql_query("SELECT ... WHERE menu.weekid = '$selectweek' AND menu.mealtimeid = '$mealtime'");
    
        echo "<table>
                <tr>
                  <th> </th>
                  <th> </th>
               </tr>
               <tr>
                 <td><strong>$mealname</strong></td>
                 <td>";
        while($info2 = mysql_fetch_array( $sqlmeasurement2 )) { 
            echo $info2['title'], '<br/>';
        } 
        echo    '</td>
               </tr>
             </table>';
    }
    
    ouptutMeal($selectweek, 1, 'breakfast');
    ouptutMeal($selectweek, 2, 'lunch');
    

    Or you could use a different query to get all the information at once, and loop through it:

    $q = "SELECT title, mealtimeid, mealtimename 
          FROM ... 
          WHERE menu.weekid = '$selectweek' 
          ORDER BY menu.mealtimeid";
    

    You can then iterate through the results, assembling them into, say, a 2D array based on using mealtimename as a key. e.g.

    $mealInfo = array()
    
    while($info = mysql_fetch_array( $result )) { 
        $mealInfo[$info['mealtimename'][] = $info;
    } 
    
    foreach ($mealInfo as $mealName => $mealData) {
        ouptutMeal($mealName, $mealData);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a menu panel with jQuery that can be
I am trying to create a menu using anchor tags, and they should butt
I am trying to create a menu that slides up from the bottom. It
I'm trying to create a horizontal menu with a thick border bar that shows
I am trying to create a webpage where users can insert a pin (like
I'm trying to create a simple WYSIWYG editor that will allow users to select
I'm trying to create a menu system that allows you to go backward and
I am trying to create a navigation menu similar to that of Stack Overflow
I'm trying to create a context menu, so that when you right click the
OK, so. I'm trying to create a dropdown menu of sorts using fadeToggle(). http://westrock.juggernautwebsites.com/

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.