Cless Posted October 27, 2007 Share Posted October 27, 2007 Hello. If you had a Private Messaging Inbox system, and had a check box beside each Private Message, and at the top, there was a 'Delete Selected Private Message' option, how would you loop the data so it deletes each selected Private Message, and what would the value of the check box be? The ID of the Private Message? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75044-solved-multi-private-message-deletion/ Share on other sites More sharing options...
GingerRobot Posted October 27, 2007 Share Posted October 27, 2007 Yeah, if you set the value of the checkboxes to be the ID of the private message, and make the checkboxes an array, you can use the implode function on the checkbox array, and then use the mysql IN clause to delete them all. More efficient than looping through and doing a separate query for each. Something like: <?php $ids = implode(",",$_POST['checkboxes'];//assuming numerical IDs. If alphanumeric, use "','" as glue. mysql_query("DELETE FROM `yourtable` WHERE `id` IN ($ids)")or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/75044-solved-multi-private-message-deletion/#findComment-379484 Share on other sites More sharing options...
Cless Posted October 27, 2007 Author Share Posted October 27, 2007 I see. Thanks. Though, how would you change them into an array? Quote Link to comment https://forums.phpfreaks.com/topic/75044-solved-multi-private-message-deletion/#findComment-379488 Share on other sites More sharing options...
GingerRobot Posted October 28, 2007 Share Posted October 28, 2007 Set the names like: <input type="checkbox" name="checkbox[]" value="<?php echo $id;?>" > Quote Link to comment https://forums.phpfreaks.com/topic/75044-solved-multi-private-message-deletion/#findComment-379702 Share on other sites More sharing options...
Cless Posted October 29, 2007 Author Share Posted October 29, 2007 Ah. Exactly like that? Would the names be checkboxes[<?PHP echo $id; ?>], or just checkboxes[]? Quote Link to comment https://forums.phpfreaks.com/topic/75044-solved-multi-private-message-deletion/#findComment-380594 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.