Welcome Guest, Not a member yet? Register   Sign In
Extracting data from a result() array of objects.
#3

[eluser]intractve[/eluser]
There are two options in CI for multiple rows,
result() and result_array()

take the following as the case result

id value allowed
1 foo true
2 bar false
3 tasty true

in your controller the result set is got by
Code:
$query = $this->db->get('table');
$rows = $query->result();

//You can directly send this result set to your view
$data['rows'] = $rows;
// This is just for example but you can do this directly in the first step itself.
//call the view

$this->load->view('view',$data);

Now your view has the variable $rows

Then in your view you can do
Code:
<table>
<tbody>
&lt;? foreach($rows as $row): ?&gt;
<tr>
<td>&lt;?=$row->id?&gt;</td>
<td>&lt;?=$row->value?&gt;</td>
<td>&lt;?=$row->allowed?&gt;</td>
</tr>
&lt;? endforeach; ?&gt;
</tbody></table>

Will print out a table with the above values.

A guide for the alternate syntax used above is here
PHP Alternate Syntax

Hope this helps.


Messages In This Thread
Extracting data from a result() array of objects. - by El Forum - 12-16-2009, 06:26 PM
Extracting data from a result() array of objects. - by El Forum - 12-16-2009, 06:37 PM
Extracting data from a result() array of objects. - by El Forum - 12-17-2009, 10:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB