[eluser]mrh[/eluser]
Ok I'm new too so this may have errors. In my model:
Code:
// Define values to send back
$data = array();
$data['appCount'] = 0;
$data['appData'] = array();
// Run query
// Run the query
$query = $this->db->query( $theQuery );
$count = $query->num_rows();
if( $count>0 )
{
$data['appCount'] = $count;
foreach( $query->result() as $row )
{
// Note stuffing each row as an array in my $data['appData'] return
$data['appData'][$row->id] = $row->projectName;
}
}
return $data;
So that is in the model.
In the controller:
Code:
// Get admin portal data
$data = $this->data_model->getAdminPortalData();
// Load the view
$this->load->view( 'header', $menuData );
$this->load->view( 'admin_view', $data );
$this->load->view( 'footer', $menuData );
Finally in the view. In this case I'm specifically populating the array in the model return so that I can use it in a drop down list on a form:
Code:
<div id="portalblockinfo">
<?php echo form_open( 'admin_portal/editappl' ); ?>
Select application to edit: <?php echo form_dropdown('activeapps', $appData, '' ); ?>
<br>
<input id="submit" type="submit" value="Go" />
<?php echo form_close(); ?>
</div>
But I could have easily done a php for to access the data in the array
Code:
<?php for($i=0; $i<count($appData); $i++) { ?>
<?php echo $appData[$i][1] ?>
<?php } ?>
I did $appData[$i][1] to get the projectName from the array. See the query above. Obviously just echoing the array contents will result in everything being on the same line. So you could add a <br> after each echo.
The basic difference between my code and yours is that in my model I create the array as a separate element of the $data passed to the view.