...

View Full Version : Resolved Notice: Object of class stdClass could not be converted to int



Dan13071992
01-16-2012, 11:04 PM
hi guys, im getting an error:



Notice: Object of class stdClass could not be converted to int in /home/tacticsc/domains/360-tactics.co.uk/public_html/crimewave/includes/inc-functions.php on line 108


it is really bugging me as i cant figure out what the problem is, and i just keep looking over line 108 and cant seem to find the problem, line 108 is:


if ($now_online > $most_online){

the whole code is:



$most_online=mysql_fetch_object(mysql_query("SELECT mostonline FROM site_stats WHERE id='1'"));

$timenow=time();

$now_online=mysql_num_rows(mysql_query("SELECT * FROM users WHERE online > '$timenow'"));

if ($now_online > $most_online){
mysql_query("UPDATE site_stats SET mostonline='$now_online' WHERE id='1'");

}


if anyone could point out what the problem is/give me a bit of help to figure this one out, that would be great.

Thanks

Dan

BluePanther
01-16-2012, 11:31 PM
Hi Dan. I remember talking to you about how to use objects with mysql_fetch_object :p.

$most_online is an object with the property mostonline. So, you would use $most_online->mostonline.

But, I would let a mysql update query do all the work here. Something like:


UPDATE site_stats SET mostonline=(SELECT COUNT(*) FROM users WHERE online>$timenow) WHERE id=1 AND mostonline<(SELECT COUNT(*) FROM users WHERE online>$timenow)

Haven't tested that query, but I think it'll work. You should look into the more advanced features of mysql like I suggested :)

Dan13071992
01-16-2012, 11:33 PM
will test it now and post back to you, i didnt think it could be done using the COUNT in mysql, but as you recommended the other day, i will carry on looking into these mysql features :)

cheers BP will post back shortly.

Dan13071992
01-16-2012, 11:36 PM
it seems to be working :)

thanks BP :)

BluePanther
01-16-2012, 11:50 PM
No problem :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum