Hi
I'm trying to use the max(field) query result as a value for a variable.
$sql= "select max(id) from process";
Is there a way to take this only result and give it to the variable?
Thank you,
$sql = "select max(id) as id from process"; $res = mysql_query($sql); if ($res) { $row = mysql_fetch_array($res); echo "MAX = {$row['id']}"; } else { echo mysql_error(); }
give that a shot, should do the trick for you.
But why do you want it? I hope that you don't want to use it as a key in an insert because it is possible that two scripts get the same id if it is run at the same time. If this is how you want to use it look at auto_increment in SQL and mysql_insert_id in PHP.
Thanks a lot drew010, that solved it.
Thanks Piranha for the info, I'm using auto_increment cause I thought it will be safer.
ThanQ
So, when you insert new rows, you do not list the 'id' column in your column list & values, right?
bradgrafelman wrote:So, when you insert new rows, you do not list the 'id' column in your column list & values, right?
Sorry for the delay in responding. I don't know if I understood correctly your question, but I'm using it as a field identifier for updating/deleting records.