[thelist] SELECTing and auto_increment field

Andrew Forsberg andrew at thepander.co.nz
Thu Sep 13 17:06:59 CDT 2001

Hi all

There's got to be a really simple solution that I'm overlooking here. 
I'd like to know what the auto_incremented field of an insert into a 
mysql table is, but preferably without having to run a hokey select 
after the insert. At the moment I'm doing this:

INSERT INTO applications
	, timestamp
	, customer_name
	, '" . $goofy_array[timestamp] ."'
	, '" . $goofy_array[customer_name] ."'

and then, to get the id, I'm doing this:

FROM applications
WHERE timestamp = '" . $goofy_array[timestamp] . "'
AND customer_email = '" . $goofy_array[customer_email] . "';

I'm fairly confident there couldn't be a duplicate timestamp/email 
combination here, but it looks like way to round-about an approach. 
Can anyone please suggest a way to return the id with the insert 
statement (in mysql), or anything more elegant than the above?

Thanks again,

Andrew Forsberg
the pander - http://thepander.co.nz/
uberNET - http://uber.net.nz/

More information about the thelist mailing list