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..... Quote 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? Quote 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.. :'( Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.