CodeIgniter Forums

Full Version: Display content in table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Diegosf93[/eluser]
Hello, i have a doubt i get info at the db and i want to format it in a table in the view archive but i´m not convinced at the idea of put php code in the view, exists another way to do this?

El Forum

[eluser]TWP Marketing[/eluser]
Do your formatting in a model, or in the controller and only send the formatted data to the view.
However, sometimes you must put php processing in a view, for instance a foreach() loop to write a list or html table. The code police will not be overly upset with this, because they do it themselves, sometimes...

El Forum

[eluser]Diegosf93[/eluser]
Thanks for your fast reply!

El Forum

[eluser]PhilTem[/eluser]
As by design: How you present your data should be handled in the view. Therefore you need to use PHP to create your table (i.e. loop over the results and format them how you want it) in the view.

Grab the data in the controller by calling the model and send the data (probably an array of arrays or objects) to the view which will make a table, an ul/ol or something else out of it Wink