MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old May 10th, 2008, 06:37 PM
drtduarte drtduarte is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 drtduarte User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 46 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 13th, 2008, 01:18 AM
drtduarte drtduarte is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 drtduarte User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 46 sec
Reputation Power: 0
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...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Delete several records in several tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway