Hello

$sql="SELECT MAX(`id`) FROM `users` WHERE `energy`=0"; $result=mysql_query($sql) or die(mysql_error()); while ($obj = mysql_fetch_object($result)) { print_r($obj); print_r($obj->MAX('id')); echo '<br>'; $obj->MAX('id'); } stdClass Object ( [MAX(`id`)] => 110 ) 

Fatal error: Call to undefined method stdClass :: MAX () in Z: \ home \ localhost \ www \ bd.php on line 18

How to be? It was possible to use mysql_fetch_array () and select 1 element of the array.

    1 answer 1

    Can somehow call the field, and then refer to it. For example, something like that?

     $sql="SELECT MAX(`id`) AS max_id FROM `users` WHERE `energy`=0"; $result=mysql_query($sql) or die(mysql_error()); while ($obj = mysql_fetch_object($result)) { print_r($obj); print_r($obj->max_id); echo '<br>'; //$obj->MAX('id'); - это вообще что? } //stdClass Object ( [MAX(`id`)] => 110 ) - и это? 
    • stdClass Object ([MAX ( id )] => 110) this was the result of print_r. And $ obj-> MAX ('id') it tried to get the value of the object. I got everything. Thanks. - zloctb