RE: [PHP] MySQL selecting the maximum value from a column
| From: | Martin Towell | Date: | Tue, 05 Feb 2002 23:14:56 +0000 |
| Subject: | RE: [PHP] MySQL selecting the maximum value from a column | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83650@lists.php.net to get a copy of this message | ||
what happens if you do this?
$result = mysql_query("SELECT MAX(Thought_Num) as Thought_Num FROM
quotes",$db);
I'm thinking that the column name in your original query is being called
"MAX(Thought_Num)" and not "Thought_Num".
Martin
-----Original Message-----
From: Melanie Gann [mailto:mgann@second-street.com]
Sent: Wednesday, February 06, 2002 10:12 AM
To: php-general@lists.php.net
Subject: [PHP] MySQL selecting the maximum value from a column
Thank you all you listeners out there. I'll try to be respectful of your
time and patience, and apoligize in advance for my "greeness" - I am 2
weeks into PHP/MySQL.
I am trying to select the higest value from the column Thought_Num below.
But it returns nothing.
<?PHP
$db = mysql_connect("localhost", "root");
mysql_select_db("DynaSite",$db);
$result = mysql_query("SELECT MAX(Thought_Num) FROM quotes",$db);
$myrow = mysql_fetch_array($result);
print "the result is $myrow[Thought_Num]";
?>
If I change my select to something that without the MAX (e.g. Select from
quotes where DocID=1), the code works fine.
Thanks in advance for your help.
Regards,
Melanie
Second Street Web Design
http://www.second-street.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php