Hi there everyone!
I need to delete abandoned cart ID's(older than 30 days) and while I'm doing that, I need to also delete and cart contents that may exist for the abandoned cart ID that is being deleted)
Usually, I would do:
SELECT FROM carts WHERE > 30 days
WHILE{
$cart_id = get this cart ID
DELETE FROM cart_contents WHERE cart_id = $cart_id
DELETE FROM carts WHERE id = $cart_id LIMIT 1
}
But I've begun wondering if there's a more streamlined way of doing this. Could I modify the single delete query of the carts to also delete any cart_contents where 'cart_id' matches the cart's 'id' being deleted?
What I mean is, is there an easier way to do this:
$q_delcarts = "DELETE FROM carts WHERE modified < '$thirtydays'";
$r_delcarts = mysqli_query ($link, $q_delcarts) or die('Catastrophic failure [Super secret code ftr834]');
While doing this for each record that gets deleted above?
$q_delcartconts = "DELETE FROM cart_contents WHERE token = '$token_from_carts_record_being_deleted_above'";
$r_delcartconts = mysqli_query ($link, $q_delcartconts) or die('Catastrophic failure [Super secret code ftr4829]');
Or do I just need to keep doing:
QUERY ~> LOOP (DELETE CHILDREN ~> DELETE PARENT)?
Thanks for your time!