Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Help deleting all rows

$
0
0

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 />"; 
}


}

Viewing all articles
Browse latest Browse all 13200

Trending Articles