Welcome Guest, Not a member yet? Register   Sign In
How to return a result array value without using foreach. Possible?
#1

[eluser]Gwarrior[/eluser]
There are explicit reasons why I cannot use a foreach statement to return values, but after doing a query

Example:
Code:
$query = $this->db->get_where(blah...)
$data['example'] = $query->result_array();
$this->load->view('example', $data);

I am unable to retrieve my results individually. In this case, I am querying all fields for a specific ID, and I want to use the results as follows (which there will always be multiple of, yet the number will remain small):

Code:
<input type="text" name="content" value="<?php echo $example['example'][0]; ?>" />

Why would this not work? Shouldn't this return the 1st value under the column 'example'? I would assume the result_array() function is generating a multi-dimensional array to use, and shouldn't I be able to access it as I am trying to above? If not, is there a way to accomplish this?

I would give you guys my source code for the project, but it's very longwinded and I'm sure this example will suffice.

Thanks!
#2

[eluser]Colin Williams[/eluser]
It would be $example[0]['column']
#3

[eluser]BrianDHall[/eluser]
And a var_dump on $example should reveal the construction of the array for you as well, so it'll be easy for you to see how you need to refer to a specific element.




Theme © iAndrew 2016 - Forum software by © MyBB