Reputation: 672
I am declare my array as public
class Doctor extends CI_Controller {
public $prescription_drug = array();
.....
}
I need array like following
Array
(
[0] => Array
(
[drugdoze] => 8
[drugname] => 80
[drugsize] => 5
[drugtype] => 1
[duration] =>
[rx_duration] => 2
[rx_instruction] => 3
[rx_special_note] => “test 1”
)
[1] => Array
(
[drugdoze] => 4
[drugname] => 10
[drugsize] => 5
[drugtype] => 3
[duration] => 1
[rx_duration] => 2
[rx_instruction] => 3
[rx_special_note] => “test 2”
)
[2] => Array
(
[drugdoze] => 1
[drugname] => 13
[drugsize] => 5
[drugtype] => 3
[duration] => 1
[rx_duration] => 2
[rx_instruction] => 3
[rx_special_note] => “test 3”
)
)
How can I append following array with
[3] => Array
(
[drugdoze] => 1
[drugname] => 13
[drugsize] => 5
[drugtype] => 3
[duration] => 1
[rx_duration] => 2
[rx_instruction] => 3
[rx_special_note] => “test 3”
)
I have a public function
public function prescription_selected_drug_session()
{
$prescription_data= array(
'drugdoze' => $this->input->post("drugdoze"),
'drugname'=> $this->input->post("drugname"),
'drugsize' => $this->input->post("drugsize"),
'drugtype' =>$this->input->post("drugtype"),
'duration'=> $this->input->post("duration"),
'rx_duration' => $this->input->post("rx_duration"),
'rx_instruction'=>$this->input->post("rx_instruction"),
'rx_special_note' => $this->input->post("rx_special_note")
);
array_push($this->prescription_drug,$prescription_data);
}
I call the function using ajax. But the value of $this->prescription_drug is overwriten every times not appended.
Can anyone help me?
Upvotes: 0
Views: 1401
Reputation: 20469
Php is stateless. Every ajax request creates a new instance of Doctor
.
You will need to persist the data in session or database, or aggregate client side
Upvotes: 1