Welcome Guest, Not a member yet? Register   Sign In
iterating through a mysql table
#1

[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.
#2

[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;
}




Theme © iAndrew 2016 - Forum software by © MyBB