Hi, i need the highest number present in a column of a table in a database. In MySQL, no problem; in PHP, i tried to use: $ciccio=mysql_query("SELECT MAX(id_rubrica) FROM rubrica"); it doesn't work! ("$ciccio=Resource id #3" is the response) then i tried: mysql_query("SELECT MAX(id_rubrica) AS ciccio FROM rubrica"); this also doesn't work ($ciccio is empty). What is wrong? What can i do? Thanks in advance
try this $result = mysql_query("SELECT MAX(id_rubrica) FROM rubrica");
$ciccio = mysql_fetch_row($result)
That should work
had that wron sorry try it this way
$result = mysql_query("SELECT MAX(id_rubrica) FROM rubrica");
$row = mysql_fetch_row($result);
$ciccio = $row["MAX(id_rubrica)"];
Thanks, but.. it still doesn't work! I tried with your suggestion (enumerated array mysql_fetch_row($result) together with $ciccio = $row[0] 'cause this is the sintax for enumerated array) and also with associative array (mysql_fetch_array($result) together with $ciccio = $row["MAX(id_rubrica)"] or $ciccio = $row["id_rubrica"]), but nothing seems to work. Why in MySQL is all ok with a simple query and in PHP seems impossible to do? Re-thanks to all. Tiziano
Here's the answer:
$max = mysql_query ( "SELECT MAX(id_rubrica) FROM rubrica" ); $val = mysql_result( $max,rubrica.id_rubrica );
// $val will be the MAX value in the column id_rubrica of the table rubrica