Freid001 Posted July 27, 2013 Share Posted July 27, 2013 (edited) Hi, so I have created some code to delete all rows from my database when an if condition is met. The code is supposed to delete all rows where the account = $account. However it only deletes 1 row when there are many rows to delete.If I echo the row id then all the rows are echoed. So not sure what I am doing wrong. $query = $db->prepare("SELECT `ww_user_pm`.id, `ww_user_pm`.to_account FROM `ww_user_pm` WHERE `ww_user_pm`.to_account=:account"); $query->execute( array( ':account'=>$account ) ); while ($row=$query->fetch(PDO::FETCH_ASSOC)){ if($account==$row['to_account']){ $query = $db->prepare("DELETE FROM `ww_user_pm` WHERE id=:id"); $query->execute(array(':id'=>$row['id'])); echo "Deleted pm: ".$row['id']."<br />"; }else { echo "Cant delete pm: ".$row['id']."<br />"; } } Edited July 27, 2013 by Freid001 Quote Link to comment Share on other sites More sharing options...
Solution Freid001 Posted July 27, 2013 Author Solution Share Posted July 27, 2013 Actually this will do the trick: $query = $db->prepare("DELETE FROM `ww_user_pm` WHERE to_account=:account"); $query->execute(array(':account'=>$account)); echo "All private messaged deleted!"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.