php : manually create a array -


new update

how write array output this: array(1) { [0]=> object(stdclass)#29 (15) { ["cals"]=> string(11) "1545.616024" } }

old update

i trying manually insert value in array if db resulting 0 results.

i trying create manually array stores value model function stores

public function fetch_lifestyeactivity_byid($activitydate, $uid) {          ----          ----         $query = $this->db->order_by('calorie_activity.ordering', 'asc')->get_where('calorie_activity', array('creater_id' => $uid,'activity_date' => $activitydate, 'parent_id =' => '625'));         $data = array();         if ($query->num_rows() > 0) {             foreach ($query->result() $row) {                 $data[] = $row;             }             return $data;         }         return false;     } 

i creating controller this

  $data["lifestyle_activity_query"] = array(      "cals"  => "6"  );  $this->load->view('weight_lose/activities', $data); 

& in view page while retrieving getting exception

 foreach ($lifestyle_activity_query $row) {   echo $row->cals; } 

exception getting as:

a php error encountered  severity: notice  message: trying property of non-object 

note: need on modifying controller logic(please not tell change view page code)

your error comes fact you've array , try use object. cast array object can used such in view.

$data["lifestyle_activity_query"] = array(      "cals"  => "6"  );  $data["lifestyle_activity_query"] = (object) $data["lifestyle_activity_query"]; echo $data["lifestyle_activity_query"]->cals; // -> 6 

edit update :

$val['cals'] = '1545.616024'; $arr[0] = (object) $val; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -