superbogel Posted September 23, 2010 Share Posted September 23, 2010 Hi Guys, I need help I have setup a code recently : this is the code : $za['MIN(spec_positionid)'] and it gave me an error saying : Cannot use object of type stdClass as array but if I change to this : $za->spec_positionid it works, but I need to get the MIN value from the database. can someone please help. this is very urgent for me..... Link to comment https://forums.phpfreaks.com/topic/214177-need-help-cannot-use-object-of-type-stdclass-as-array/ Share on other sites More sharing options...
trq Posted September 23, 2010 Share Posted September 23, 2010 $za is an object, not an array. Where do you define it? Link to comment https://forums.phpfreaks.com/topic/214177-need-help-cannot-use-object-of-type-stdclass-as-array/#findComment-1114448 Share on other sites More sharing options...
superbogel Posted September 23, 2010 Author Share Posted September 23, 2010 here is the definition : $ra = db_query("SELECT MAX(spec_id), MAX(spec_positionid), MIN(spec_id), MIN(spec_positionid) FROM spec"); $za = db_fetch_object($ra); if ($a->spec_positionid!=$za['MIN(spec_positionid)']) { $page_content .= '<a href="spec.php?idcat=$a->spec_id&movecatpos=$a->spec_positionid&movecat=up"><img src="images/uparrow.png" border="0" align="absmiddle">up</a>'; } else { $page_content .=' '; } this code : $za['MIN(spec_positionid)'] shows error, but I don't understand how to change it into $za->(get the min value from the DB). please help.. :'( Link to comment https://forums.phpfreaks.com/topic/214177-need-help-cannot-use-object-of-type-stdclass-as-array/#findComment-1114452 Share on other sites More sharing options...
trq Posted September 23, 2010 Share Posted September 23, 2010 Use aliases in your query. $ra = db_query("SELECT MAX(spec_id) AS max_spec_id, MAX(spec_positionid) AS max_spec_positionid, MIN(spec_id) AS min_spec_id, MIN(spec_positionid) AS min_spec_positionid FROM spec"); Then use.... $za->min_spec_positionid Link to comment https://forums.phpfreaks.com/topic/214177-need-help-cannot-use-object-of-type-stdclass-as-array/#findComment-1114456 Share on other sites More sharing options...
superbogel Posted September 23, 2010 Author Share Posted September 23, 2010 Use aliases in your query. $ra = db_query("SELECT MAX(spec_id) AS max_spec_id, MAX(spec_positionid) AS max_spec_positionid, MIN(spec_id) AS min_spec_id, MIN(spec_positionid) AS min_spec_positionid FROM spec"); Then use.... $za->min_spec_positionid THIS SOLVE THE PROBLEM!!! YOU ARE THE MAN!! THANK YOU VERY MUCH Link to comment https://forums.phpfreaks.com/topic/214177-need-help-cannot-use-object-of-type-stdclass-as-array/#findComment-1114598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.