|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Delete several records in several tables
Dear Friends,
I'm a mysql newbie, but I know that's easy what I want. I'm runnig this query: $result = mysql_query("SELECT orders_id FROM orders where orders_status= '4' and date_purchased < DATE_SUB(UTC_TIMESTAMP(), INTERVAL 30 MINUTE)") or die(mysql_error()); Now I want to delete records from 4 different tables with all orders_id from the first query Any ideas? Regards David |
|
#2
|
|||
|
|||
|
I got it working:
$result = mysql_query("SELECT orders_id, date_purchased FROM orders where orders_status= '4' and date_purchased< DATE_SUB(UTC_TIMESTAMP(), INTERVAL 20 MINUTE)") or die(mysql_error()); $row = mysql_fetch_array( $result ); while ($row = mysql_fetch_array( $result )) {$delete = mysql_query(" DELETE orders, orders_products, orders_products_attributes, orders_status_history, orders_total FROM orders LEFT JOIN orders_products ON orders_products.orders_id = orders.orders_id LEFT JOIN orders_products_attributes ON orders_products_attributes.orders_id = orders.orders_id LEFT JOIN orders_status_history ON orders_status_history.orders_id = orders.orders_id LEFT JOIN orders_total ON orders_total.orders_id = orders.orders_id WHERE orders.orders_id = '$row[orders_id]'") or die(mysql_error());} Now the only problem is that the time interval choosen is not respected sometimes, I don't understand why... |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Delete several records in several tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|