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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:52:57+00:00 2026-06-09T14:52:57+00:00

I have a table for a menu like below (see the HTML section): http://jsfiddle.net/6YZzb/

  • 0

I have a table for a menu like below (see the HTML section):

http://jsfiddle.net/6YZzb/

I want to convert the data to a looping nested menu. I want it to be like:

http://jsfiddle.net/aRSsZ/

This outputs it as HTML:

<ul>
    <?php echo $renderProductMenuItemLv1; ?>
</ul>​

and the relevant PHP code:

if($result = $mysqli->query("SELECT * FROM myTable WHERE type='Business_Line_Product_Level_1' AND parent='37' ORDER BY order_id ASC"))
{
    while($row = $result->fetch_array())
    {
        $productLv1Title = $row["title"];
        $productLv1Body = $row["body"];
        $productLv1OriId = $row["id"];

        if($result2 = $mysqli->query("SELECT * FROM page WHERE type='Business_Line_Product_Level_2' AND parent='$productLv1OriId' ORDER BY order_id ASC"))
        {
            while($row = $result2->fetch_array())
            {        
                $productLv2Title = $row["title"];
                $productLv2Body = $row["body"];
                $productLv2OriId = $row["id"];

                $renderProductMenuItemLv2 .= '
                <li>
                    <a href="businessLineProductLv2.php?p='. $productLv2Id .'">
                        '. $productLv2Title .'
                    </a>
                </li>
                ';
            } // eof while row
        } // eof if result

        $renderProductMenuItemLv1 .= '
        <li>
            <a href="businessLineProductLv1.php?p='. $productLv1Id .'">
                '. $productLv1Title .'
            </a>
            <ul>
                '. $renderProductMenuItemLv2 .'
            </ul>
        </li>
        ';
    } // eof while row
} // eof if result
$result->free_result();

​
But the result is I get additional sub menu items on every menu item.

How can I fix my code?

  • 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-09T14:52:59+00:00Added an answer on June 9, 2026 at 2:52 pm

    It seems that you might always be appending to $renderProductMenuItemLv2 when you actually need to reset the string with every iteration of the outer loop. Maybe all you need is a

    $renderProductMenuItemLv2 = '';
    

    above the line if($result2 = $mysqli->query("SELECT * FROM page ... ?

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

Sidebar

Related Questions

I have a table having hierarchical menus like id parent_id name 1 0 menu
I have a left side navigation menu on my page.. using url.action like below..
I have a table td like below. if i use this.xml the below value
I have table in MySQL where the data are stored like: table_1 +-------+-------+ |field_0|field_1|
i have table unser it i have one td with elemets inside the menu
I have 11 records in the Menu table, only 1 with a PageID set
Hi i have a table strcture for my menu, and i need to be
I have some simple markup: <table> <tr> <td>Menu Item</td> </tr> </table> <div> <table> <tr>
I have an initial table view that I created as the initial menu within
I have a table that caches data (shared hosting so no memcached) to a

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.