InLikeMe Posted December 2, 2008 Share Posted December 2, 2008 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 More sharing options...
ranjuvs Posted December 2, 2008 Share Posted December 2, 2008 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 https://forums.phpfreaks.com/topic/135135-how-to-retrieve-max-value/#findComment-703840 Share on other sites More sharing options...
InLikeMe Posted December 2, 2008 Author Share Posted December 2, 2008 Thanx a looooooot....solved Link to comment https://forums.phpfreaks.com/topic/135135-how-to-retrieve-max-value/#findComment-703852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.