CodeIgniter Forums
iterating through a mysql 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: iterating through a mysql table (/showthread.php?tid=24165)



iterating through a mysql table - El Forum - 11-02-2009

[eluser]bhbutter123[/eluser]
I understand how to do the queries in the models but how would I do the following in the view(I am assuming that is where I would do it.)

while($row = mysql_fetch_array($result)){
echo"$row";
}

how would i go ahead and do that because I assume that the model is only to get the database's table data and not to display it at all.


iterating through a mysql table - El Forum - 11-02-2009

[eluser]umefarooq[/eluser]
hi from your model return database fetched rows pass it to controller and then controller will pass to view
Code:
model
function get_rows(){
$query = $this->db->get('table');

return $query->result()

}

controller
$data['rows'] = $this->mymodel->get_rows();
$this->load->view('my_view',$data);

view
foreach($rows as $row){
echo $row->colname;
}