Jump to content

Help deleting all rows


Freid001

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.