visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: mysql selecting max


By: Bernard France  Date: 26/09/2005 09:24:53  English  Points: 20 Status: Answered
Quality : Excellent
how to retrieve the max of a column over a MySql database in PHP ? I can't get the returned value...
By: VGR Date: 26/09/2005 09:30:59 English  Type : Answer
Hello ;-)

This is a very basic operation, and is more than well described in the documentations for PHP or MySql (www.mysql.com and www.php.net/manual/en/ or the like) so I suppose your problem is the "classical" alias problem :

if you do

select max(somecol) from thetable;

then you will have the problem of retrieving "max(somecol)" as the name of the returned field. This can become tricky if the computation involves quotes, and can even get confusing if the RDBMS returns "computed" in stead of the formula itself ;-))

So I suggest to always alias your computed columns, even if a simple count(*), like this :

select sum(somecol) AS a from thetable;



this way, you will probably have no problems at all retrieving the column named 'a' in the returned result set ;-)

Note that some "RDBMS" do not support "AS" (Oracle, not to name it) but accept the aliasing without 'AS', like in "select sum(somecol) a from thetable")

Best regards

Do register to be able to answer

EContact
browser fav
page generated in 290.699960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page