Page 1 of 1
get the max value from mysql
Posted: Fri Jun 24, 2005 2:28 am
by jackie111
here is the sql:
$resultc=mysql_db_query("webstat","select Max(cat) from info design");
how can i get the max(Cat)?
thanks
Jackie
Posted: Fri Jun 24, 2005 2:45 am
by Chris Corbyn
I'd alias the max(cat) if I were you to make it easier....
I have no idea how many records that is returning or what the data is so probably most generically....
Code: Select all
$resultc=mysql_db_query("webstat","select Max(cat) as m from info design");
$max_cat = array();
while ($row = mysql_fetch_array($resultc)) {
$max_cat[] = $row['m'];
}
print_r($max_cat);
Posted: Fri Jun 24, 2005 2:58 am
by jackie111
the Max must will only return one line, i think we do not need to use while loop, can we use some function to get it?
thanks
Jackie
Posted: Fri Jun 24, 2005 3:01 am
by Chris Corbyn
Code: Select all
$resultc=mysql_db_query("webstat","select Max(cat) as m from info design");
$max_cat = mysql_result($resultc, 0, 'm');
EDIT | The PHP manual on
http://www.php.net/ is the BEST resource for PHP available.... please use it

Posted: Fri Jun 24, 2005 3:25 am
by jackie111
thanks so much!