php mysql max() question

A. W. Wright diamondmagic at users.sourceforge.net
Sun Apr 12 15:13:14 MST 2009


Craig White wrote:
> just want the max of an integer field ultimately into a variable.
>
> <?php
>   $MaxSalesOrders = 'SELECT MAX(orderno) FROM salesorders;';
>   mysql_connect("$HOST", "$USER", "$PASSWD");
>   mysql_select_db("lighting_unlimited");
>   $MaxSalesOrdersResult = mysql_query($MaxSalesOrders);
>   mysql_close();
>   echo var_dump($MaxSalesOrdersResult) . " - " . \
>    $MaxSalesOrdersResult;
> ?>
>
> seems pretty straight forward. In mysqlclient, the answer is of course
> returned - perhaps as a row, I'm never quite sure.
>
> The code above returns the following in a browser...
>
> resource(6) of type (mysql result) - Resource id #6
>
> and I've been trying all sorts of things 'SELECT AS...' and Googled for
> several hours and I'm sort of convinced that what is being returned from
> the sql query is neither an array, nor string and has to be converted
> into a variable that is useful to me.
>
> Anyone know how to do this (i.e. without pear-db)?
>
> Craig
>   
mysql_query (and mysqli_query) doesn't actually give you the resuly,
just a pointer to it. Use the mysql_fetch_assoc (returned array indexed
by column name) or mysql_fetch_row (indexed by column order) function to
get that, and see http://us2.php.net/mysql_query for more information.

Austin Wright.



More information about the PLUG-discuss mailing list