Jc John
Jc John

Reputation: 1859

how to store my query data into array in codeigniter controller

regarding in query from the model, i got already the values and store it from a variable, now i want it to be stored from a data array for further use, how can i do this, i am in controller from codeigniter.

Here is my controller full code:

  public function move_data($queue_id) {
        $data = array();
        $user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
        $getqueuedata = $this->Clinic_model->queue_data($queue_id,$user);
        //echo json_encode($getqueuedata);

        $data = array (
        'queue_id' => $getqueuedata['queue_id'],
        'user_id' => $getqueuedata['user_id'],
        'clinic_id' => $getqueuedata['clinic_id'],
        'order_num' => $getqueuedata['order_num'],
        'patient_id' => $getqueuedata['patient_id'],
        );
  }

when i //echo json_encode($getqueuedata); uncomment this line, and comment the array storing, i will have this:

[{"user_id":"102","clinic_id":"2","order_num":"1","patient_id":"7","status":"2","time_sched":null,"queue_id":"1"}]

in my full code, i got error, i dont know how to store the values of my query from array.

Upvotes: 1

Views: 1056

Answers (1)

Nidhi
Nidhi

Reputation: 1539

function 'queue_data` return result like this :

//$getqueuedata =  json_decode($json,true);

Array ( [0] => Array ( [user_id] => 102 [clinic_id] => 2 [order_num] => 1 [patient_id] => 7 [status] => 2 [time_sched] => [queue_id] => 1 ) ) 

So you can store data as this way:

$data = array (
       'queue_id' => $getqueuedata[0]['queue_id'],
       'user_id' => $getqueuedata[0]['user_id'],
       'clinic_id' => $getqueuedata[0]['clinic_id'],
       'order_num' => $getqueuedata[0]['order_num'],
       'patient_id' => $getqueuedata[0]['patient_id'],
       );
print_r($getqueuedata);

If your function return array object:

$data = array (
       'queue_id' => $getqueuedata[0]->queue_id,
       'user_id' => $getqueuedata[0]->user_id,
       'clinic_id' => $getqueuedata[0]->clinic_id,
       'order_num' => $getqueuedata[0]->order_num,
       'patient_id' => $getqueuedata[0]->patient_id,
       );

Upvotes: 4

Related Questions