![]() |
Show database results in a table - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Show database results in a table (/showthread.php?tid=24818) |
Show database results in a table - El Forum - 11-20-2009 [eluser]max123[/eluser] How can i display results of a single column in a database table, in a 4 columns table in a view file Show database results in a table - El Forum - 11-20-2009 [eluser]sofwan[/eluser] You can try : in your controller : function view_table() { $query = "select name from student"; $data['resultx']=$this->db->query("$query"); $this->load->view('view_student',$data); } in your view (view_student.php) <? foreach ($resultx->result() as $row) { echo $row->name."<br /> ; } ?> Show database results in a table - El Forum - 11-21-2009 [eluser]max123[/eluser] You didn't get my question. Please read da question. All the Values from a single column of a table should display in a 4 column table in the view according to the order in the table column Show database results in a table - El Forum - 11-21-2009 [eluser]renownedmedia[/eluser] I think the OP needs to learn basic PHP before trying CI. Show database results in a table - El Forum - 11-21-2009 [eluser]Alninio[/eluser] When you say 4 columns in order do you mean like a newspaper column layout where you fill the first column then the second then the third and finally the fourth or do you mean row by row? i.e. result 1 result 5 result 9 result 13 result 2 result 6 result 10 result 14 result 3 result 7 result 11 result 15 result 4 result 8 result 12 result 16 or result 1 result 2 result 3 result 4 result 5 result 6 result 7 result 8 result 9 result 10 result 11 result 12 result 13 result 14 result 15 result 16 Either way you can put a counter inside your loop and add in the row/cell tags at the right places. <edited for layout> Show database results in a table - El Forum - 11-21-2009 [eluser]jedd[/eluser] [quote author="max123" date="1258799286"]How can i display results of a single column in a database table, in a 4 columns table in a view file[/quote] Please show us how you do this in normal / raw PHP - post your existing code - and then we can show you the changes you'd make to work better under CodeIgniter, okay? Show database results in a table - El Forum - 11-21-2009 [eluser]John_Betong[/eluser] [quote author="max123" date="1258799286"]How can i display results of a single column in a database table, in a 4 columns table in a view file[/quote] A quick search for an old thread on five columns revealed: http://ellislab.com/forums/viewthread/63078/ Show database results in a table - El Forum - 11-22-2009 [eluser]max123[/eluser] I found the answer. First the records from the database should take in to an array. There after by using 2 for loops properly showing in the table can be done. Anyways thanx all for ur support Show database results in a table - El Forum - 09-28-2012 [eluser]karltingume2007[/eluser] hey guys!!! initially i was not part of this problem and solution on showing database results in a table but i was following up closely because i was working on something similar. i have a problem on loading the content of my database unto my view. here is my code: The controller: Code: class Addressbook extends CI_Controller { The view: Code: <?php A function in my model: Code: function get_entries() { all of these bring me the following error: Code: A PHP Error was encountered please somebody tell me how to convert an object of a class into a string or better still an advanced solution to this problem or how to go about it. Thank you all in advance. |