0

I have this menu structure:

<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li><a href="#">One more separated link</a></li>
    </ul>
</li>

I want to be able to generate it from my current table structure:

sequence
page_title
page_url
parent

In the above structure, parent will equal sequence so for all top levels, my query would include WHERE parent = '' then all child items, the query would include: WHERE parent = '[SEQUENCE]'.

1 Answer 1

1

If I'm understanding the question correctly. You're looking to sort your menu items by parent, followed by child menu items.

For the parent items, you could make the parent column equal itself.

Ex.

id | sequence | page_title | page_url | parent
----------------------------------------------
1  | 1        | parent     | url      | 1
3  | 3        | child 2    | url      | 1
2  | 2        | child 1    | url      | 1

The query to sort the results would be:

SELECT * FROM menu_items ORDER BY parent, sequence

In your code to create the parent/child menu, you could check to see if the parent = id to determine if the item is a parent item. This help?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.