Welcome Guest, Not a member yet? Register   Sign In
list menu and submenu from two table
#1
Question 

Hi, I am new in codeigniter and I need help off course for one problem.

I have two tables, menu and submenu.

Table menu:
id_menu, menu_name
1, Menu 1
2, Menu 2
3, Menu 3

Table submenu;
id_sub, id_menu, sub_name
1,1, Sub 1.1
2,1, Sub 1.2
3,1, Sub 1.3
4,2, Sub 2.1
5,3, Sub 3.1
6,3, Sub 3.2

How I can using MVC get in view next list:

Menu 1
 Sub 1.1
 Sub 1.2
 Sub 1.3
Menu 2
 Sub 2.1
Menu 3
 Sub 3.1
 Sub 3.2

Thanks in advance
Reply
#2

You're probably looking for more specifics, but, as a start:
- Build a model which uses query builder or db->query() to retrieve the list from the tables. Depending on your comfort level and whether you already have the SQL (or a stored procedure) to retrieve the list, you have to make some trade-offs between the number of queries to the database (or the complexity of the query/queries) and the amount of work you'll do in PHP to build the list. The fact that the data is in two tables (rather than one) tells me that someone may have had a specific query in mind, but I could be wrong.
- Your controller would load the model and call the method to retrieve the list, then load a view, passing the list to the view

If you're going to use this in multiple places on your site, you may want to use a library to load the model, retrieve the data, and load the data into a partial view (or return the data), so you can load the library to get the menu in whatever controller needs to do so.
Reply
#3

(10-21-2015, 12:55 PM)mwhitney Wrote: You're probably looking for more specifics, but, as a start:
- Build a model which uses query builder or db->query() to retrieve the list from the tables. Depending on your comfort level and whether you already have the SQL (or a stored procedure) to retrieve the list, you have to make some trade-offs between the number of queries to the database (or the complexity of the query/queries) and the amount of work you'll do in PHP to build the list. The fact that the data is in two tables (rather than one) tells me that someone may have had a specific query in mind, but I could be wrong.
- Your controller would load the model and call the method to retrieve the list, then load a view, passing the list to the view

If you're going to use this in multiple places on your site, you may want to use a library to load the model, retrieve the data, and load the data into a partial view (or return the data), so you can load the library to get the menu in whatever controller needs to do so.

How to write model to list all data from one table and for each row to list data from another table related for that id_menu?
Reply
#4

(10-24-2015, 04:42 AM)vladakg Wrote:
(10-21-2015, 12:55 PM)mwhitney Wrote: You're probably looking for more specifics, but, as a start:
- Build a model which uses query builder or db->query() to retrieve the list from the tables. Depending on your comfort level and whether you already have the SQL (or a stored procedure) to retrieve the list, you have to make some trade-offs between the number of queries to the database (or the complexity of the query/queries) and the amount of work you'll do in PHP to build the list. The fact that the data is in two tables (rather than one) tells me that someone may have had a specific query in mind, but I could be wrong.
- Your controller would load the model and call the method to retrieve the list, then load a view, passing the list to the view

If you're going to use this in multiple places on your site, you may want to use a library to load the model, retrieve the data, and load the data into a partial view (or return the data), so you can load the library to get the menu in whatever controller needs to do so.

How to write model to list all data from one table and for each row to list data from another table related for that id_menu?


Look at this you will need to make some changes but should point you in the right direction.

Dynamic Multi-level CSS Menu with PHP and MySQL. SEO Ready
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB