hi, i've got this site, that has a form on it now the guy wants it to have a specific start number and i wondered if anyone could tell me how to select from the database the last number entered and then add 1 to it, hope this explains ok, thanks Martin
funnily enough, you answered your own question. In SQL, do this:
$res=mysql_query("select id from table order by id desc"); $nid=mysql_fetch_assoc($res); $nid=$nid['id']+1;
and then $nid will have the next largest id available.
You can't do that, because if two people use the same form at the same time, they would get the same number...
You should solve this problem on your database manager using a trigger.
Hope this helps.
Care to elaborate?
Actually Vincent, it seems that row locking for the database would handle that potential conflict. That assumes, of course, that a database supporting row locking was being used.
OTOH I am still a newbie trying to grok the essence of what's going on around here.
That also assumes that you'd dare to keep a database lock on rows in a stateless HTTP environment.
Assuming that you could keep a database-lock even though the database-connection that requested the lock has been destroyed, how would you determine when the lock should be removed if you have no clue about what the webpage is doing?