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
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];

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.