Jax2 Posted October 3, 2009 Share Posted October 3, 2009 I am hoping someone can help me here. I have a script which adds a record into mysql and also sends an email to the operator saying a new order has been added. I am trying to show the operator what the order # is (by the ID column, which is set to INT, 10, not null, auto-inc, key) ... first, I tried this: $order=($row['ID']+1); I had 5 records in the database. When I echoed $order, it showed me 5+1 So then I tried: $order=($row['ID']++); even though I was pretty sure that was the same thing, but this time, instead of showing me 5+1, it showed me 5, the total number of records I have. So, what I would like to figure out is how I can take those 5 rows, find the last record number and add 1 to it, and show the total as a new variable ... I can get last record number easy enough with select * from foo order by ID DESC limit 1, which gives me the last, but I cannot get the +1 to work for the life of me ... Could someone tell me what the heck I'm doing wrong? Thanks! Link to comment https://forums.phpfreaks.com/topic/176344-some-help-with-adding-1-to-last-record-number-to-show-what-next-will-be/ Share on other sites More sharing options...
Matthew Herren Posted October 3, 2009 Share Posted October 3, 2009 try : $order = ($row['ID'])+ 1; Link to comment https://forums.phpfreaks.com/topic/176344-some-help-with-adding-1-to-last-record-number-to-show-what-next-will-be/#findComment-929449 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 You should probably try something like... <?php $conn = mysql_connect('host', 'user', 'pass'); $conn = mysql_select_db('database'); $insert = mysql_query("INSERT INTO table (field, field2) VALUES ('value', 'value2')", $conn); $id = mysql_insert_id($conn); echo 'Last inserted item has the id ' . $id; ?> Link to comment https://forums.phpfreaks.com/topic/176344-some-help-with-adding-1-to-last-record-number-to-show-what-next-will-be/#findComment-929591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.