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 4592608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:33:49+00:00 2026-05-21T22:33:49+00:00

EXAMPLE CODE <?php require_once(‘class_library/pdo.php’); $pdoConnection = new sdb(‘web_structure’); $select = $pdoConnection->query(SELECT main_menu.href AS main_href

  • 0

EXAMPLE CODE

<?php
require_once('class_library/pdo.php');
$pdoConnection = new sdb('web_structure');
$select = $pdoConnection->query("SELECT main_menu.href AS main_href
    , main_menu.link_name AS main_link
    , sub_menu.href AS sub_href
    , sub_menu.link_name AS sub_link
  FROM main_menu
  LEFT JOIN sub_menu ON main_menu.id = sub_menu.main_menu_id 
  ORDER BY main_menu.position ASC");

while($row = $select->fetch())
{
    $href = $row["main_href"];
    $link_name = $row["main_link"];
    $sub_href = $row["sub_href"];
    $sub_link_name = $row["sub_link"];  

//MAIN MENU (display only once)
    echo "      <li><a href=\"$href\">$link_name</a>\n";

//SUB MENU (show all related results)
    echo "       <ul>\n";
    echo "        <li><a href=\"$sub_href\">$sub_link_name</a></li>\n";
    echo "       </ul>\n";
    echo "      </li>\n";
}
?>

OUTPUT

Services
– service 1

Services
– service 2 …etc

Products
– product 1

Products
– product 2 …etc


I would like

Services
– service 1
– service 2

Products
– product 1
– product 2

  • 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-21T22:33:50+00:00Added an answer on May 21, 2026 at 10:33 pm
    <?php
    require_once('class_library/pdo.php');
    $pdoConnection = new sdb('web_structure');
    $select = $pdoConnection->query("SELECT main_menu.href AS main_href
        , main_menu.link_name AS main_link
        , sub_menu.href AS sub_href
        , sub_menu.link_name AS sub_link
      FROM main_menu
      LEFT JOIN sub_menu ON main_menu.id = sub_menu.main_menu_id 
      ORDER BY main_menu.position ASC, main_menu.id ASC");
    
    $p_link_name = '';
    while($row = $select->fetch())
    {
        $href = $row["main_href"];
        $link_name = $row["main_link"];
        $sub_href = $row["sub_href"];
        $sub_link_name = $row["sub_link"];  
    
    //MAIN MENU (display only once)
        if ($p_link_name !== $link_name) {
            echo "      <li><a href=\"$href\">$link_name</a>\n";
        }
    
    //SUB MENU (show all related results)
        echo "       <ul>\n";
        echo "        <li><a href=\"$sub_href\">$sub_link_name</a></li>\n";
        echo "       </ul>\n";
        if ($p_link_name !== $link_name) {
             echo "      </li>\n";
        }
        $p_link_name = $link_name;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
I'm doing a PHP site which displays code examples in various languages (C#, PHP,
Is there good example code or a test project for explaining the Model–view–presenter (MVP)
Many C++ books contain example code like this... std::cout << Test line << std::endl;
here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
There is this example code, but then it starts talking about millisecond / nanosecond
Does anyone have an example (code or a link) that will allow me to
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I see a lot of example code for C# classes that does this: public
I've gone through most of the example code and I still need some help.

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.