PDA

View Full Version : Returning the ID's of deleted rows?


Velocd
06-21-2003, 05:12 PM
I have a query that looks exactly like this:
$DB_site->query("DELETE FROM categories WHERE FIND_IN_SET('$catid',parentlist)>0");

I need to somehow return the ID's of the rows deleted from this query. Those ID's being the values of the first column auto_increment 'categoryid' of the table categories.

I need this for a later query that looks like this:

$DB_site->query("DELETE FROM images WHERE categoryid IN ($deletelist)");

$deletelist being the rows deleted in the first query, arranged in a comma seperated list using implode().

I would be very thankful if you could help. ;)

Xenon
06-21-2003, 11:02 PM
hmm i don't know if this is dooable but you can do a workaround with a query you have to run before the delete query

SELECT id FROM...
then
DELETE from cat
then
Delete from images..

Velocd
06-21-2003, 11:33 PM
True, that way wouldn't be hard, and I was about to result to that, but I was just seeing if it could be done in some other simpler trick.

Too bad it can't be done with something simple like how you can return the auto_increment id of an INSERT command using $DB_site->insert_id();

PHP needs a delete_ids(); that functions like insert_id(); but for the DELETE query (and can return many values).
* Velocd shrugs

Thanks though ;)

filburt1
06-21-2003, 11:44 PM
Such a function is a nice idea in concept but doesn't apply: insert_id() returns the newly created id of an auto_increment column. Nothing new is generated so nothing can be retrieved.