Jump to content

How to retrieve MAX value?


InLikeMe

Recommended Posts

Is there any particular PHP function which retrieves the max value of a query?

To be specific:

 

I have the query:

 $max_customer = mysql_query('SELECT max(customer_id) FROM customers'); 

 

and when I "echo" it

 echo $max_customer; 

I get "Resource id #3"

 

When I use sql functions like mysql_ fetch_ array, mysql_ fetch_ assoc inside a while loop I get the word "Array".

With mysql_ fetch_ object I get error.

 

Is there any kind of "get_value" function? which will do sth like that --> $max_customer = get_value('SELECT max(customer_id) FROM customers');

Thnx

Link to comment
https://forums.phpfreaks.com/topic/135135-how-to-retrieve-max-value/
Share on other sites

First of all you need fetch data from db using mysql_fetch_array or mysql_fetch_object

$result = mysql_query('SELECT max(customer_id) as max_cust_id FROM customers'); 

$max_customer = mysql_fetch_array($result);

echo $max_customer[0][max_cust_id];

 

 

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.