Jump to content

[SOLVED] Can't access this stdClass Object var


c_shelswell

Recommended Posts

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

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.