Jump to content

Some help with adding 1 to last record number to show what next will be?


Jax2

Recommended Posts

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!

 

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.