Jump to content

Delete all checked


web_master

Recommended Posts

Hi,

 

I got a problem to delete all the checked items here is a form:

 

<div class="MsgNameContainer"><p class="MsgName"><a href="<?php echo 'IndexInput.php?cnt=Usr&UsrID=' . $REQUEST[ 'user_id' ];?>" class="MsgName"><?php echo $REQUEST[ 'user_firstname' ] . ' ' . $REQUEST[ 'user_name' ];?></a></p></div>
		<div class="MsgDateContainer"><p class="MsgDate"><?php echo $REQUEST[ 'msg_datetime' ];?></p></div>
		<div class="MsgReadNotContainer"><p class="MsgDate"><?php echo $ReadNotRead;?></p></div>
		<div class="MsgCheckContainer"><input type="checkbox" name="msg_deleted_from[]" value="1" /></div>
		<div><input type="hidden" name="msg_id" value="<?php echo $REQUEST[ 'msg_id' ];?>" /></div>
		<div class="ClearBoth"><!-- --></div>

 

and here is the code, where I want to change in column `msg_deleted_from` 0 to 1

 

<?php 
// Delete Msg
if ( $_POST[ 'MsgDelete' ] ) {

$RemoveAll = array();
$RemoveAll = $_POST[ 'msg_deleted_from' ];
	print_r($RemoveAll);
	if ( count ( $RemoveAll ) > '0' ) {
		foreach ( $RemoveAll as $DeleteMsg ) {
			$Query = mysql_query( 'UPDATE `msg` SET `msg_deleted_from` = "' . $DeleteMsg . '" WHERE `msg_id` = "' . $_POST[ 'msg_id' ] . '" ');
				if ( !$Query ) { echo mysql_error(); exit; }
		}
	}

} // End of Msg Delete
?>

 

So, when I check all listed, its "delete" every time only one message...

 

thnx in advanced

 

T

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/
Share on other sites

What dies this output?

 

<?php 
// Delete Msg
if ($_POST['MsgDelete'] ) {
  $ids = $_POST[ 'msg_deleted_from' ];
  $sql =  "UPDATE msg SET msg_deleted_from = ' $DeleteMsg' WHERE msg_id IN(" . implode(',', $ids) . ")";
  die($sql);
  if (!mysql_query($sql)) {
    echo mysql_error(); exit; 
  }
}

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968809
Share on other sites

What dies this output?

 

<?php 
// Delete Msg
if ($_POST['MsgDelete'] ) {
  $ids = $_POST[ 'msg_deleted_from' ];
  $sql =  "UPDATE msg SET msg_deleted_from = ' $DeleteMsg' WHERE msg_id IN(" . implode(',', $ids) . ")";
  die($sql);
  if (!mysql_query($sql)) {
    echo mysql_error(); exit; 
  }
}

 

I need Array, because there is a more than messages, and as You see in form there is a checkbox, so when I want to delete multiple messeges I must to check multiple checkboxes... In this case I can delete with one submit delete all the checked messeges

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968839
Share on other sites

Thats exactly what my code does, you don't need any loop.

 

Now, again, what does it output?

 

dont work,

the $_POST[ 'msg_deleted_from' ]; is update in database that row msg_deleted_from goes from 0 to 1

but every listed (query) form have an individual ID (msg_id)

that mean, update every row where id is its own ID

 

while...{ // this is an query

<input type="checkbox" name="msg_deleted_from[]" value="1" />

<input type="hidden" name="msg_id" value="<?php echo $REQUEST[ 'msg_id' ];?>" /> // every checkbox have own ID

}

 

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968913
Share on other sites

change form to

<div class="MsgNameContainer"><p class="MsgName"><a href="<?php echo 'IndexInput.php?cnt=Usr&UsrID=' . $REQUEST[ 'user_id' ];?>" class="MsgName"><?php echo $REQUEST[ 'user_firstname' ] . ' ' . $REQUEST[ 'user_name' ];?></a></p></div>
         <div class="MsgDateContainer"><p class="MsgDate"><?php echo $REQUEST[ 'msg_datetime' ];?></p></div>
         <div class="MsgReadNotContainer"><p class="MsgDate"><?php echo $ReadNotRead;?></p></div>
         <div class="MsgCheckContainer"><input type="checkbox" name="msg_deleted_from[]" value="<?php echo $REQUEST[ 'msg_id' ];?>" /></div>
         <div class="ClearBoth"><!-- --></div>

and

foreach($_POST['msg_deleted_from'] as $id){
         $sql =  "UPDATE msg SET msg_deleted_from = '1' WHERE msg_id = '$id')";
         etc.
}

 

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968966
Share on other sites

change form to

<div class="MsgNameContainer"><p class="MsgName"><a href="<?php echo 'IndexInput.php?cnt=Usr&UsrID=' . $REQUEST[ 'user_id' ];?>" class="MsgName"><?php echo $REQUEST[ 'user_firstname' ] . ' ' . $REQUEST[ 'user_name' ];?></a></p></div>
         <div class="MsgDateContainer"><p class="MsgDate"><?php echo $REQUEST[ 'msg_datetime' ];?></p></div>
         <div class="MsgReadNotContainer"><p class="MsgDate"><?php echo $ReadNotRead;?></p></div>
         <div class="MsgCheckContainer"><input type="checkbox" name="msg_deleted_from[]" value="<?php echo $REQUEST[ 'msg_id' ];?>" /></div>
         <div class="ClearBoth"><!-- --></div>

and

foreach($_POST['msg_deleted_from'] as $id){
         $sql =  "UPDATE msg SET msg_deleted_from = '1' WHERE msg_id = '$id')";
         etc.
}

 

 

 

sasa, excellent!!!!

 

Thank You!!!!

Link to comment
https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968981
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.