Jump to content

Help deleting all rows


Go to solution Solved by 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 />"; 
}


}
Edited by Freid001
Link to comment
https://forums.phpfreaks.com/topic/280567-help-deleting-all-rows/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.