web_master Posted December 1, 2009 Share Posted December 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/ Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968809 Share on other sites More sharing options...
web_master Posted December 1, 2009 Author Share Posted December 1, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968839 Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 Thats exactly what my code does, you don't need any loop. Now, again, what does it output? Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968905 Share on other sites More sharing options...
web_master Posted December 1, 2009 Author Share Posted December 1, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968913 Share on other sites More sharing options...
sasa Posted December 1, 2009 Share Posted December 1, 2009 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. } Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968966 Share on other sites More sharing options...
web_master Posted December 1, 2009 Author Share Posted December 1, 2009 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!!!! Quote Link to comment https://forums.phpfreaks.com/topic/183551-delete-all-checked/#findComment-968981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.