Newbie needs help using MAX function
Posted: Sun Jul 08, 2007 5:41 pm
I'm a newbie having trouble understanding the proper use of the MAX function. I've seen a lot of examples online, which I've tried to apply in my case, but so far no luck. Could someone please look at the latest incorrect ways that I've tried to use the function below and tell me where I'm going wrong?
Thanks.
My first attempt:
In the following test example that I've been working with, I'm trying to calculate the maximum value of a numeric INT field called count in a table called Britishism:
I'm using $result2 above instead of $result because this portion of the script is actually nested inside the following WHILE function that has already used a variable called $result:
while ($row = mysql_fetch_assoc($result)) {
}
My second attempt:
I also tried something like the following, without using MAX directly in a SELECT statement, but instead, calling the function during the execution of a WHILE statement, as in:
}
...but that didn't work either.
Thanks.
My first attempt:
In the following test example that I've been working with, I'm trying to calculate the maximum value of a numeric INT field called count in a table called Britishism:
Code: Select all
$sql="SELECT MAX(count) as $maxcount FROM Britishism";
$result2 = mysql_query($sql);
echo "Highest count is ".$result2;while ($row = mysql_fetch_assoc($result)) {
}
My second attempt:
I also tried something like the following, without using MAX directly in a SELECT statement, but instead, calling the function during the execution of a WHILE statement, as in:
Code: Select all
while ($row = mysql_fetch_assoc($result)) {
$maxcount = MAX($row['count']);
echo "Highest value in count field is ".$maxcount;...but that didn't work either.