Welcome Guest, Not a member yet? Register   Sign In
Convert object value to int ?
#1

[eluser]Berserk[/eluser]
hi there, i'm a php newbie and i'm writing an small app using CI but i get some err.

myDB
post:
Code:
post_id
FK_post_cat_id
title
content
viewed

cat:
Code:
id
name

At my model, i created function get_viewed and get_max_view

Code:
function get_viewed($id)
{
$this->db->select('viewed','viewed');
$query = $this->db->get_where($this->post_table,array('post_id'=>$id));
$m = $query->result();
return $m;
}


Code:
function get_max_viewed($id)
{
$this->db->select_max('viewed','maxviewed');
$query = $this->db->get_where($this->post_table,array('FK_post_cat_id'=>$id));
return $query->row();
}

my controller
Code:
$maxview = $this->details->get_max_viewed($catid)

my view:

Code:
<?php
$p=($post->post_viewed/$maxview)*100;
echo "$p%";
?>




but i got error, system said cannot convert $maxview from object to int. How to fix this problem ?
#2

[eluser]gon[/eluser]
$maxview is an object, containing 2 properties: 'viewed' and 'maxviewed'.
Use the appropiate one to do the calculation.

Strangely, you do that correctly with $post, but not with $maxview.
#3

[eluser]Berserk[/eluser]
thanks, fixed this problem. i forgot about properties Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB