Welcome Guest, Not a member yet? Register   Sign In
How can I parse this array within my controller?
#1

[eluser]matches[/eluser]
Can someone explain to me how to parse this result array?

Array ( [0] => Array ( [id] => 126 [user_id] => 2 [number] => 1515 [address_1] => Address [address_2] => Address [city] => City [zip] => 0 ) )

Here is the model method:

Code:
function get_slideshow_by_id($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('shows');
        return $query->result_array();
    }

Here is the controller method:

Code:
function current_show()
    {
$this->load->model('slideshow_model');
$slideshow_id = $this->uri->segment(3);
$query = $this->slideshow_model->get_slideshow_by_id($slideshow_id);

print_r($query);
echo $query->number;

$data['main_content'] = 'slideshow/current';
$this->load->view('includes/base', $data);
    }

Thanks for your help.
#2

[eluser]solid9[/eluser]
Not tested but try,
Code:
$query[0]['city'];

Use foreach to loop.
#3

[eluser]matches[/eluser]
Great thanks! I swear I tried that Smile

Just out of curiosity. Why is the result returned like that? Although this solution works, it could be prettier.

Thanks again
#4

[eluser]Aken[/eluser]
Read the user guide, it explains what types of data each method returns. You should be using row() or row_array() when fetching a single row.




Theme © iAndrew 2016 - Forum software by © MyBB