php - How do I access an Array Value using it's Key in a view -
i've been working on method email users data , i'm having trouble printing data in view. can access data in bulk format displays within html table user.
model:
function getemaildata($usersid){ $this->db->select('*'); $this->db->from('symptom'); $this->db->where('userid', $usersid); $symptomstate = $this->db->get(); $result = $symptomstate->result_array(); return $result; } function getemailbmdata($usersid){ $this->db->select('*'); $this->db->from('bowelmovement'); $this->db->where('userid', $usersid); $bmstate = $this->db->get(); $result = $bmstate->result_array(); return $result; }
controller:
function senddataasemail(){ $uid = $this->session->userdata('id'); $uname = $this->session->userdata('username'); $uemail = $this->input->post('email_data'); $data = array( 'username'=> $uname, ); $data['symptomdata'] = $this->poomonitormodel->getemaildata($uid); $data['bmdata'] = $this->poomonitormodel->getemailbmdata($uid); $data['symptomcount'] = $this->poomonitormodel->gettotalsymptomcount($uid); $data['bmcount'] = $this->poomonitormodel->gettotalbmcount($uid); var_dump($data); $contents = $this->load->view('pooemail.php',$data,true); $this->email ->from('#', '#') ->to($uemail) ->subject('#') ->message($contents) ->set_newline("\r\n") ->set_mailtype('html'); $this->email->send(); }
view:
<p> <?php foreach($symptomdata $data){ foreach($data $nestdata){ echo $nestdata; }; };?> </p> <p> <?php foreach($bmdata $bmdata){ foreach($bmdata $nestbmdata){ echo $nestbmdata; }; };?> </p>
currently echo $nestdata
outputs data complete string this, access single attribute $nestdata['symptomdate']
:
462016-04-1402:00burningoesophagus7vomitting 562016-04-1405:00tinglinggallbladder3vomitting 662016-04-1410:00shootingsmallintenstine8vomitting 1362016-04-2016:47crampgallbladder1gurgling noise 1462016-04-2016:58tinglingrectum1strange tingling sensation in raer 1962016-04-2017:41crampileum2cramping 2062016-04-2017:42crampanus7it whistles 2162016-04-2017:42cramprectum7it whistles
but access specific value can put each bit of data table data cell it's easier read user.
thanks!
the keys in $data
name of var in view. so, $data['symptomcount']
in controller accessed $symptomcount
in view.
what depends on type. if $symptomcount
object (class) $x = $symptomcount->some_property
. if array - $symptomcount['some_index']
iterate them so
foreach($symptomdata $symptom){ echo $symptom['symptomdate']; }
Comments
Post a Comment