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