Welcome Guest, Not a member yet? Register   Sign In
foreach loop in model
#1

[eluser]ns8814[/eluser]
Ok so what. I understand how to pass the model to the controller. Then send the $data to the view. Then typically do the foreach loop in the view to output your results. The question I have is can you create the foreach loop in the model so when you get to the view it looks nice and neat and only needs to echo $dataVariable. In case I am not explaining it clearly I posted the code below.
Code:
~~~~~~~~~~MODEL ~~~~~~~~~
function get_customers()
{
     $query = $this->db->get('customers');
foreach($query->result() as $row)
{
echo '<option value="'.$row-&gt;customerID.'">'.$row->FirstName.$row->LastName.'</option>';
    
}
    }  

~~~~~~Controller~~~~~
$data["customerlist"]=$this->estimates_model->get_customers();

~~~~~~~VIEW~~~~~~~~~~`
&lt;?php echo $customerlist;?&gt;
This is how I currently have it setup and I thought it should work however nothing outputs on the view. Not sure if this is bad practice anyhow but it seems to make sense to try to do it this way if I can get it to work.


Messages In This Thread
foreach loop in model - by El Forum - 06-26-2012, 07:04 PM
foreach loop in model - by El Forum - 06-26-2012, 07:12 PM
foreach loop in model - by El Forum - 06-27-2012, 01:19 AM
foreach loop in model - by El Forum - 06-27-2012, 07:46 AM
foreach loop in model - by El Forum - 06-27-2012, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB