Welcome Guest, Not a member yet? Register   Sign In
DMZ object in foreach
#4

[eluser]slowgary[/eluser]
I'm confused Smile

Just to make sure I understand... based on your query, it looks like you're selecting all orders. This would lead me to believe that you're attempting to show many orders in your view. Also, there is one product and one sheet (whatever that is Smile per order.

The query looks fine, however it appears that you're only creating one order() object in your controller to pass to your view. I prefer to work with array, since I grew up in functional land, but if you plan to pass a collection of order objects to your view, I would expect to see something like this in your controller:
Code:
$this->load->model('order_model');
$orders = $this->order_model->get_all_orders();
foreach($orders as $order)
{
     $temp = new Order();
     $temp->set_properties($order);
     $data['orders'][] = $temp;
}

$this->load->view('orders', $data);
Then in your view:
Code:
<?php foreach($orders as $order): ?>
<tr>
     <td>&lt;?php echo $order->id; ?&gt;</td>
     <td>&lt;?php echo $order->product_name; ?&gt;</td>
     <td>&lt;?php echo $order->something_else; ?&gt;</td>
</tr>
&lt;?php endforeach; ?&gt;

Does that make sense for what you're trying to do?


Messages In This Thread
DMZ object in foreach - by El Forum - 09-04-2010, 07:45 AM
DMZ object in foreach - by El Forum - 09-05-2010, 08:16 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:05 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:22 AM
DMZ object in foreach - by El Forum - 09-05-2010, 09:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB