Freid001 Posted July 27, 2013 Share Posted July 27, 2013 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 />"; } } Link to comment https://forums.phpfreaks.com/topic/280567-help-deleting-all-rows/ Share on other sites More sharing options...
Freid001 Posted July 27, 2013 Author 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!"; Link to comment https://forums.phpfreaks.com/topic/280567-help-deleting-all-rows/#findComment-1442394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.