1

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.

3
  • 1
    Can you elaborate on how your code "doesn't work"? What were you expecting, and what actually happened? If you got an exception/error, post the line it occurred on and the exception/error details. Please edit these details in or we may not be able to help. Commented May 22, 2017 at 10:59
  • @FrankerZ i want only to store the values of $getqueuedata that is the result of my query into array, but i am doing wrong. whats the correct?. i got error . Commented May 22, 2017 at 11:07
  • you can use row_array() in queries Commented May 22, 2017 at 12:44

1 Answer 1

4

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,
       );
Sign up to request clarification or add additional context in comments.

2 Comments

thnks for understanding my question.. ii'll try this
hello sir i got error Message: Cannot use object of type stdClass as array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.