Finding the highest value - newbie question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ade
Forum Newbie
Posts: 4
Joined: Tue Dec 30, 2003 6:20 pm
Location: UK

Finding the highest value - newbie question

Post by ade »

Hi,

I'm new to php and I'm trying to build a small MySQL application for my website.

I need to find the highest numeric value (integers)in a table column. so far I have let Dreamweaver MX help me define a recordset which I can see works ok. Next I tried to use the max() function on the recordset which I believe should work as the recordset is an array.

I tried:
$maxnumber = max($recordset);
but that gave me errors when it ran.

Next I tried:
$maxnumber = max(array(recordset));
which, when echoed tells me that the value in $maxnumber is not an integer as I was expecting but the string "Resource id #2".

Please can someone help me to get the highest integer out of the table column. Do I need to define a recordset first? Am I using the wrong syntax? I have tried the online php docs but am not having much luck.

Thanks in advance.

ade
uk
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

User avatar
swirlee
Forum Newbie
Posts: 7
Joined: Fri Dec 26, 2003 12:08 am

Post by swirlee »

Why not just use MySQL's MAX() function?
ade
Forum Newbie
Posts: 4
Joined: Tue Dec 30, 2003 6:20 pm
Location: UK

Post by ade »

Thanks both. Now I knew what to look for I have found all the SQL function docs. MAX() does exactly what I need.

ade
uk
Post Reply