brandon000 Posted April 8, 2008 Share Posted April 8, 2008 Buddy ol' Pals...please tell me why the following delete statement doesn't work. I keep getting "Query was empty". When I run the SQL with the "Select" statement just to verify any results and it works fine but when I set it to DELETE it doesn't work at all. ??? if ((isset($_GET['Delete_ProductID'])) && ($_GET['Delete_ProductID'] != "")) { $DeleteProductID=$_GET['Delete_ProductID']; mysql_query("DELETE FROM product_sizes as p WHERE Exists (Select StyleID From product_styles as m Where m.ProductID=".$DeleteProductID." and p.StyleID=m.StyleID)"); } Link to comment https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/ Share on other sites More sharing options...
craygo Posted April 8, 2008 Share Posted April 8, 2008 Won't work. Something about deleting a row you are currently searching. http://bugs.mysql.com/bug.php?id=5123 Ray Link to comment https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/#findComment-512173 Share on other sites More sharing options...
brandon000 Posted April 8, 2008 Author Share Posted April 8, 2008 Thanks for replying Craygo. I guess it's a limitation with current MySQL. What alternative do you recommend to achieve the DELETE statement to emmulate the EXISTS clause? Link to comment https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/#findComment-512205 Share on other sites More sharing options...
craygo Posted April 8, 2008 Share Posted April 8, 2008 Well you can query first then run the delete $check = "SELECT StyleID FROM product_styles WHERE ProductID = '$DeleteProductID'"; $ch_res = mysql_query($check) or die(mysql_error()); $found = mysql_num_rows($ch_res); if($found > 0){ $row = mysql_fetch_assoc($ch_res); $styleid = $row['StyleID']; $delete = "DELETE FROM product_sizes WHERE StyleID = '$styleid'"; mysql_query($delete) or die(mysql_error()); Hope I interpolated that correctly. Ray Link to comment https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/#findComment-512210 Share on other sites More sharing options...
brandon000 Posted April 8, 2008 Author Share Posted April 8, 2008 Excellent! Thanks Ray Link to comment https://forums.phpfreaks.com/topic/100173-delete-from-exists-issue/#findComment-512229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.