How to get a data value from stdclass object? If I used print_r
I get stdclass object..
my expected output is like this:
paper : 21
scissors :22
rock : 12
Actual output :
stdClass Object (
[player_item] =>
[total] => 1
)
stdClass Object (
[player_item] => paper
[total] => 39
)
stdClass Object (
[player_item] => rock
[total] => 32
)
stdClass Object (
[player_item] => scissors
[total] => 12
)
here is my code
Model:
$this->db->select('player_item, COUNT(player_item) as total');
$this->db->group_by('player_item');
$query = $this->db->get('rps');
return $query->result();
controller:
$this->load->model('rps_model');
$data3['query']=$this->rps_model->rps_stat();
$this->load->view('rps_view',$data3);
view:
foreach($query as $row )
{
print_r($row);
}
In your view:
foreach($query as $row) {
if(trim($row->player_item) != '') {
echo $row->player_item . ' : ' . $row->total . '<br/>';
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.