c_shelswell Posted April 21, 2009 Share Posted April 21, 2009 Hi I've got a database class which is all working great for me however I've just tried to get a MAX figure from mysql and now I can seem to access the returned value my code to get the value is: <?php $data = array('fields'=>'MAX(crt_order_id)', 'table'=>'cart'); $nextCrt = $db->selectFromDB($data); echo "<pre>"; print_r ($nextCrt); echo "</pre>"; ?> which prints: Array ( [0] => stdClass Object ( [MAX(crt_order_id)] => 5522 ) ) normally i'd just been getting what I wanted by $nextCart[0]->crt_order_id but the MAX seems to have messed things up for me. Don't suppose anyone can help? Cheers Link to comment https://forums.phpfreaks.com/topic/155067-solved-cant-access-this-stdclass-object-var/ Share on other sites More sharing options...
Mchl Posted April 21, 2009 Share Posted April 21, 2009 Don't suppose anyone can help? You're right. j/k $object->{MAX(crt_order_id)} could work... but I'm not sure really? Does your database class allow for column aliases? That would be probably best way. Something like $data = array('fields'=>'MAX(crt_order_id) AS maxOrderId' , 'table'=>'cart'); Link to comment https://forums.phpfreaks.com/topic/155067-solved-cant-access-this-stdclass-object-var/#findComment-815612 Share on other sites More sharing options...
c_shelswell Posted April 21, 2009 Author Share Posted April 21, 2009 Nice one thanks the php method didn't work out but the database alias worked a treat. Thanks very much Mchl Link to comment https://forums.phpfreaks.com/topic/155067-solved-cant-access-this-stdclass-object-var/#findComment-815616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.