Outputting results to a table - 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: Outputting results to a table (/showthread.php?tid=21877) |
Outputting results to a table - El Forum - 08-23-2009 [eluser]zuluanshee[/eluser] I have a list of countries, europe, say. I want to output them in alphabetical order, but within each column so the table will look like this Code: <table> I guess i understand how to program it, but how do I use the table library? I looked at the documentation but i don't know which stuff happens in the model and which happens in the view. Here is what I have: model Code: <?php Code: <?php foreach($countries as $row):?> controller Code: <?php Outputting results to a table - El Forum - 08-23-2009 [eluser]zuluanshee[/eluser] I found a workaround, but its unsatisfactory, because it contains echoed tags '<td>'; I know you're not supposed to echo html, but I can't think of a better way off the top of my head. view Code: <table id="countries"> Outputting results to a table - El Forum - 08-23-2009 [eluser]jedd[/eluser] The Table library is a curious thing - it generates HTML in the Controller. For this reason (plus it's not that good at doing anything out of the ordinary) a lot of people ignore it, and end up writing their own view partials that generate the table(s) they want. Over time you can abstract them out such that they become nicely generalised, but there's nothing hugely wrong with writing a view file that just generates this particular table. Outputting results to a table - El Forum - 08-23-2009 [eluser]alboyd[/eluser] So what is your question? is it to do with the three columns and having them as a b c // d e f // g h i like that or?? It should be fairly easy to do that. I would take your countries data in the view and figure out how many columns you want, then based on the number of countries in the countries array you can figure out how many to put in each column, then you just do a foreach and output them, creating a new column when a counter reaches the predetermined value (number of countries per column). Just make sure also that your query orders the countries in alphabetical order.. let me know if you need some more explanation or if I am not understanding your question... EDIT: and as Jedd said - I wouldn't bother using the table library/helper IMO it's just easier to write the table HTML yourself. There should be no need for you to "echo" HTML though? |