I've got a table (MySQL) with a field called: 'java_num'. It's a varchar(4). It's going to have a number in that field anywhere from 001 to 999. How can I make a query in PHP that searches through that field and finds the largest number?
U probably mean:
$sql = "SELECT MAX(java_num) FROM table"; $res = mysql_query($sql); $max = mysql_result($res,0);
why is it a varchar if its a number field? You'd be better off with int or smallint.
Then its just a case of
SELECT java_num FROM <table_name> ORDER BY java_num DESC;
Well, how can I make a field that is an integer that will always be 3 numbers long:
002, 014, 235, etc. It MUST be 3 numbers long. I can't figure out how do do that. Any idea?
read up on ZEROFILL in the mySQL manual on Numeric Types.
ok, I've got the zerofill thing going on and working correctly...
I've got this code now:
$highest = mysql_query("SELECT MAX(java_num) FROM events");
But this isn't giving me the number. It says it's an array. How can I get the highest number into a variable?
$result = mysql_query('SELECT MAX(java_num) FROM events') or exit(mysql_error()); $max = mysql_result($result, 0); echo $max;
thanks a bunch!