Creating dynamic sidebar menu with Mysql and AdminLTE Bootstrap Template

To create dynamic and exciting sidebar menu, you need a database for the storage and website templates that facilitate in making the layout (In this article, I use adminLTE bootstrap, read my other tutorial here or check adminLTE official website for more information).

how to create dynamic sidebar menu with mysql and adminLTE bootstrap

In this tutorial you will find information about creating and managing dynamic sidebar menu with mysql and adminLTE Bootstrap.

 Creating Table menu with myqsl for dynamic sidebar menu 

Add new table in your database with name dynamic_menu , copy this table structure below to you

Column NameData typeLengthPrimary KeyNot nullauto increment

Or run this mysql script with include example menu


Column NameDescription
idId menu , auto increment
parent_idEvery menu has parent_id
titleMenu title
urllink url to your page
menu_orderorder menu
status1 or 0 value for active or deactive
levelUser level
iconbootstrap menu icon
descriptionTitle description

 Creating PDO Class to connect php and mysql 

Create php file as pdo_db.php

 Creating dynamic sidebar menu in adminLTE Bootstrap Template 

In adminLTE code, we will find code below to create sidebar menu

Change these code with my code below to creating dynamic sidebar menu

You can modify my code as you wish, if any question about how to create dynamic sidebar menu in adminLTE bootstrap, please leave comment 🙂

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.


 Add your comment
  1. Eneko Anasagasti

    Thank you for sharing this code!
    There is a small typo in the query ….FROM menu ORDER BY menu_order’);
    should be ….FROM dynamic_menu ORDER BY menu_order’); instead.

  2. i want to know how to set user permission view for certain module

  3. Terima kasih tutorialnya, bermanfaat buat saya.

    mungkin dikoreksi kali querynya kurang tepat ya harusnya diganti tabelnya jangan menu, khawatir bagi yang baru belajar kebingungan kenapa tidak bisa running.

  4. many thanks for your work
    I found that it doesn’t add active class to the submenu after it was clicked.
    thanks again

  5. Mohon petunjuknya gan.
    Itu kan sub menu nya punya class ‘treeview-menu’ yah
    Kalo di template yang sub menu class nya beda-beda seperti class ‘second-level’ , ‘third-level’, ‘fourth-level’ , gimana yah caranya. saya coba utak-utik kok stuck. yang harusnya di level 1, masuk ke level 2, karena dia punya sub menu lagi. mohon arahannya, thank you

  6. Mohon bantuannya, bagaimana membuat menu dinamis seperti diatas bila menggunakan mysqli?

    Menurut agan, untuk menu bertingkat/multilevel baiknya menggunakan 1 tabel saja atau pakai 2 tabel (tbl menu dan tbl submenu).. Terima kasih sebelumnya.

  7. Mau nanya, kalau dengan menggunakan metode diatas ingin dibuat hak usernya seperti bagaimana mas Sigit? Jadi hak user atas menu disimpan pada tabel usernya seperti tutorial yang di link barusan… Mohon bantuannya…

    • iya… hak akses menu usernya disimpan di table user. Id submenunya dipisahkan dengan koma. Kemudian ketika melakukan looping sub menu , cek masing2 id sub menu apakah ada field user.

      Catatan : hak akses user yang di simpan di table user dipisahkan dengan koma. Cara aksesnya , silahkan gunakan fungsi explode pada PHP untuk dsimpan dalam array. Kemudian cek array tersebut dengan fungsi in_array

      Semoga menjawab pertanyaan 🙂

  8. Why the php code break after ‘->’ operator at $hasil=$database ->
    idk why but entire query string is not operated as well

  9. Hey, Thanks for the tutorial.

    Does the same applies if I am using the Top Navegation instead? or do i have to chane anything?


Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.