[SOLVED]newbie question: Help on "Join" and "For Each" to show results |
[eluser]Juan Velandia[/eluser]
Hello, as i'm trying to go further in PHP and CI programming I will need your help again (and again...) I want to show a list with all the sections and articles related to those sections, something like this: Solutions: - web design - Brochures - Flyers Clients: - CocaCola - Pepsi - SevenUp But I cant seem to find the right way to do it. this is what I get: Solutions: - web design Solutions: - Brochures Solutions: - Flyers Clients: - CocaCola Clients: - Pepsi Clients: - SevenUp Here's the Code The model Code: function get_section_articles() The controller Code: $data['section_articles'] = $this->section_content_model->get_section_articles(); the view Code: foreach ($section_articles->result_array() as $row): Any Ideas for a graphic designer? thanks a lot
[eluser]smilie[/eluser]
Code: Without testing, I guess you will have to use Tho' I would suggest to change DB structure and to place sections in one table, articles in another and to link them with i.e. article_section_id (which would reffer to section_id). Cheers, Smilie
[eluser]Juan Velandia[/eluser]
Hello Smilie Thanks for you quick answer, I've add these two lines in the model as you suggested Code: $this->db->group_by('section_name'); Regarding your sugestion the DB has already the two tables that you recommend: "section" and "article" and both have a "id_section" field wich connects them. I think the model could be ok, but I'm still struggling with the view. Do yoy have any further suggestions? thanks a lot and best regards!
[eluser]Juan Velandia[/eluser]
Well, it seems that It was already resolved: http://ellislab.com/forums/viewthread/158001/ Regards!
[eluser]Juan Velandia[/eluser]
After some hours dealing with this and with some previous threads I came up with he solution Model Code: function get_section_articles() controller Code: $data['section_articles'] = $this->section_content_model->get_section_articles(); view: Code: foreach ($section_articles as $section): ?>
|
Welcome Guest, Not a member yet? Register Sign In |