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 Quote Link to comment 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'); Quote Link to comment 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 Quote Link to comment 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.