SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sudden change in structure

    I am working on the menu page of a restaurant website. The structure was like this:
    Code:
    • Soup
    • Appetizers
      • Salads
      • Hot Appetizers
    • Main Courses
      • Fish
      • Meat
      • Poultry
    • Side Dishes
    • Menus
    and a link would look like this:
    Code:
    <a href="modules/site/menu.php?category_id=1&amp;group_id=1">Soup</a>
    As you can see from the anchor were the results based on two id's category_id and group_id. Clicking the link soup would result in a listing of the soups they serve, and obviously the same for the other links like salads, meat, fish, menus etc. To achieve that I used the following query and output on the result page:
    Code:
    <?php
        $category_id = filter_input(INPUT_GET, 'category_id', FILTER_SANITIZE_NUMBER_INT);
        $group_id    = filter_input(INPUT_GET, 'group_id', FILTER_SANITIZE_NUMBER_INT);
    
        $qryMenu = "SELECT MG.menu_group_id, MG.menu_group, MI.menu_item, MI.description_dut, MI.description_eng, MI.description_dut2, MI.description_eng2, MI.description_dut3, MI.description_eng3, MI.description, MI.price 
                    FROM menu_groups MG 
                    INNER JOIN menu_items MI
                    ON MG.menu_group_id = MI.menu_group_id
                    WHERE menu_category_id = $category_id
    		AND MG.menu_group_id = $group_id";
    									 
          if ($result = $mysqli->query($qryMenu)) {
              while ($row = $result->fetch_assoc()) {
                       echo "<h1>{$row['menu_group']}</h1>
                             <dl>
                               <dt>{$row['menu_item']}<span>";if ($row['price'] == "Dagprijs"){}else{echo"€";}echo"&nbsp;{$row['price']}</span></dt>
                             </dl>";
              }
          }
    ?>
    But suddenly the owner of the website would like to show the different 4 and 5 course dinners not longer as a listing but as separate items just like salads and Hot Appetizers under Appetizers and Fish, Meat and Poultry under Main Courses. Changing the database is/was not an option so I thought that including the id of each menu_item could do the trick so I changed the structure in the menu
    Code:
    • Menus
      • Menu Canton
      • Menu Szechuan
      • Pekingeend Szechuan
      • etc
    and in the anchor I added menu_id
    Code:
    <li><a href="modules/site/menu.php?category_id=4&amp;group_id=9&amp;menu_id=79">Menu Canton</a></li>
    and added the following to the result page:
    Code:
    $menu_id     = filter_input(INPUT_GET, 'menu_id', FILTER_SANITIZE_NUMBER_INT);
    
    if ($menu_id ) {
        $qryMenu .= "AND menu_item_id = $menu_id";
    }
    but that isn't working at all as you can see here when you click on one of the first four menus under menus (Theater Menu is coming from a different group). What should I adjust to make it work?

    Thank you in advance!
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if I understand your situation. Do you need to associate some items on the menu with a 4/5 course dinner option?

    If so you would need a column in the database to make that association. Whats the issue with changing the database structure??

  3. #3
    SitePoint Evangelist silver trophybronze trophy
    Join Date
    Jul 2013
    Posts
    406
    Mentioned
    22 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Hi donboe,
    I see the short/long pages suffer from theJumpingPage.htm, for instance when changing between the "Soepen" page and the "Voorgerechten" page on a 1280*1024px screen.

    It seems there is also something wrong in the calling of the pages.
    In the menu the "Soepen" page has a link to <a href="modules/site/menu.php?category_id=1&amp;group_id=1">
    and the "Salades" page has a link to <a href="modules/site/menu.php?category_id=2&amp;group_id=2" class="subitem">,
    though for both the address in the browser bar is staying at "cantonamsterdam.nl/canton-menu.php". While it is php-driven, I can't see why.

    Isn't it the easiest way to make all pages separate pages, with a php-include for the menu and other permanent parts of the page?
    Then for all changes afterwards you only have to adapt the menu-include.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •