How to do this? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to do this? (/showthread.php?tid=53503) Pages:
1
2
|
How to do this? - El Forum - 07-28-2012 [eluser]mlakhara[/eluser] You can use nested views for display. At the first level you display the categories(using foreach) and in side this you can again load another view to display the forum topics under that category. Also Data fetching can be don in the similar way using models for category and topics. This way you will get the data in the form of a nested associativ array which then can be used easily with each nested view(as the associative arrays break inside the view). How to do this? - El Forum - 07-29-2012 [eluser]Mahn[/eluser] Okay, here's a very simple example of what I'm trying to do written with procedural php. So the following code simple creates a list of categories, and the corresponding forums underneath (where the category_id = the one being displayed) Code: $query = mysql_query("SELECT * FROM categories"); Which will make something like the following: Code: • Category 1 How to do this? - El Forum - 07-30-2012 [eluser]Mahn[/eluser] bump! How to do this? - El Forum - 07-30-2012 [eluser]Aken[/eluser] http://ellislab.com/codeigniter/user-guide/database/index.html If you know how to do it with procedural code, then read into how to do DB queries with CI, and apply it to your code. You say you know the basics, but you're not trying to apply any of them. Try something, if it doesn't work, then show your code and ask specific questions, not just "how do I do this?". How to do this? - El Forum - 07-31-2012 [eluser]astroanu[/eluser] this can be easily achieved with with a foreach loop. As Aken said if you know how to do it with php its fairly simple with CI if you read the DB guide in CI How to do this? - El Forum - 07-31-2012 [eluser]mlakhara[/eluser] Oops!! I am sorry as I didn't check my mailbox for a while This is how I achieved something like this for an online survey project which had a set of question which were divide into groups called "panel". each panel had a number of question which can be of varying type(MCQ,text answer,and other things which required variable markup for each question). I divided my view at each level. at the most basic level I wrote the view for displaying a question like this Code: file -(view/question) now this view will be loaded for each question in the panel using looping Code: file -(view/question_panel) Code: <!-- This is where the question view will be looped and loaded --> So the last snippet was included in the main view that I requested, that way each level gets its seperate view system and you can tweak them easily. If its complicated you can simply use the foreach loop as you just have to show the topics and nothing fancy like this Code: foreach($categories as $category) Oh yeah as far as OOP paradigm is concerned you should carry out all your queries in model, and seperate the application logic in controller. And for this nothing is better than the CI user guide to read from.. :-) Hope this helps. |