> > Bruce Wolk wrote:
Sugapablo wrote:
> Let's say I create a new record in a table like this:
> mysql_query("INSERT INTO table (col1) VALUES
('example')",$conn);>
> ...that had an auto-incrementing, unique identifying column
named "ID"> that would be populated with a unique number upon insertion...
>
> How can I get the unique number it assigned to that record
returned for> futher use?
>
>
mysql_insert_id()
http://us2.php.net/manual/en/functio...-insert-id.php
Does mysql_insert_id() return the last record inserted by ANYONE,
or the last record inserted by the current instance?>
Jim Thomas & All,
The function that has been suggested does not seem to be what you want.
Everyone with their manuals buzz off. This requires some logic.
First, instead of relying on a one stop shop function to suit your
needs you need to think beyond this. Imagine coming to a page for the
first time that requires a customer ID. You could just rely on the dB
to auto increment but then the user does know what the value is/was.
Lastly, this is how I handle finding the last record auto incremented,
increment it, and post it for a future query (You do not always need to
rely on the system):
$query = "select cust_id from customer_data order by cust_id DESC";
$data_pointer = mysql_query($query);
if ($getID = mysql_fetch_assoc($data_pointer))
{
$lastID = $getID[cust_id];
$lastID++;
print $lastID;
}
You may need to do some formatting with the value at he end of this but
this code will lead you in the right direction.