Re: Getting a result from MAX() query
| From: | boclair | Date: | Wed, 14 Jul 2004 01:57:20 +0000 |
| Subject: | Re: Getting a result from MAX() query | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35235@lists.php.net to get a copy of this message | ||
"John W. Holmes" <holmes072000@charter.net> wrote in message
news:40F3F535.10007@charter.net...
> boclair@boclair.com wrote:
> > Would somebody be kind enough to explain why this query produces a false
result
> >
> > $latest=mysql_query("SELECT MAX(fee_recd) FROM members",$connectup)or
die
> > ("Query failed:<br>$latest<br>Error: " . mysql_error());
>
> Would you be kind enough to tell us what text mysql_error() shows?
>
> You probably just need to use an alias in your query:
>
> SELECT MAX(fee_recd) AS max_fee_recd FROM members
>
> and then you'll have $row['max_fee_recd'] when you fetch the value from
> your result set. Other wise you need to use $row['MAX(fee_recd)']...
I did reply but it seems to have gone astray.
Thanks. There no report from error() and obviously the result of the query
is not false. I was trying to solve the wrong problem which was in the PHP
statement that followed. Using your example, this was successful
$latest=mysql_query("SELECT MAX(fee_recd) FROM members",$connectup)or die
("Query failed:<br>$latest<br>Error: " . mysql_error());
while ($myrow= mysql_fetch_array($latest)){
$recentpaid=$myrow['MAX(fee_recd)'];
}
Louise