Here's something I can do, but looking for a quicker/ more efficient way.
I've got a table with 2 fields
field1 is set to primary and auto increment
field2 is set to unique
I want to insert into field2 (field1 is autoincrement) and retrieve the ID that was given to that record. If a duplicate is found (value of field2 was inserted previously) then I want to get the ID of that field.
So how would you do it?
I've got this, but it acts funny sometimes (I copied the ON DUPLICATE from somewhere and not sure how it works). The below code sometimes works and sometimes inserts duplicates.
$query = 'INSERT INTO table SET field2=\''.$value.'\' ON DUPLICATE KEY UPDATE field2=\''.$value.'\'';
$result = $this->query($query);
$genID = mysql_insert_id();