mike1313 Posted December 23, 2007 Share Posted December 23, 2007 So I'm working on my in-game mail system and when the user is in the inbox they can click a checkbox to select/deselect all messages then delete them. But the problem I have is since I'm using a while statement the checkboxes appear in the while so that a checkbox can be displayed for each record. How would I go about deleting the ones that are clicked so I can delete them? echo "<form name=mform> <table align=center> <tr> <td><b>Message</b> </td> <td width=25%> </td> <td width=25%><b>From</b> </td> <td width=25%><b>Sent</b> </td> <td>Check all?</td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td><input type=checkbox name=checkall onclick=\"checkUncheckAll(this);\"> </td> </tr>"; while ($q4 = mysql_fetch_array($query4)){ $msg = substr($q4[message], 0, 24); $msg2 = strlen($q4[message]); if($msg2 > "24"){ $msg3 = "..."; } $query5 = mysql_query("SELECT * FROM `players` WHERE `from`='$q4[id]'"); $q5 = mysql_fetch_array($query5); echo "<tr> <td width=25%><a href=mail.php?per=view&vid=$q4[id]>$q4[title]</a><br>$msg<b>$msg3</b><br><hr width=100%> </td> <td width=25%> </td> <td width=25%>$q5[username] </td> <td width=25%>$q4[date]</td> <td><input type=checkbox name=del> </tr>"; } echo "</form></table>"; Quote Link to comment https://forums.phpfreaks.com/topic/82973-solved-help-with-multiple-checkboxes/ Share on other sites More sharing options...
Barand Posted December 23, 2007 Share Posted December 23, 2007 Name the checkboxes with "[]" at the end of the name so they are posted as an array. Give the c/box a value of the record id to be deleted if checked <?php echo "<input type=checkbox name='del[]' value='$recordID'>"; ?> When form is submitted <?php $deleteList = join ("','", $_GET['del']); mysql_query ("DELETE FROM tablename WHERE id IN ('$deleteList')"); Quote Link to comment https://forums.phpfreaks.com/topic/82973-solved-help-with-multiple-checkboxes/#findComment-422008 Share on other sites More sharing options...
mike1313 Posted December 23, 2007 Author Share Posted December 23, 2007 One more thing how would I check when that same code was submitted whether theres wasnt any checkboxes checked. because normally it would be <?php if($_POST[name] == "off"){ echo "NOT CHECKED"; } ?> But that doesnt seem to work Quote Link to comment https://forums.phpfreaks.com/topic/82973-solved-help-with-multiple-checkboxes/#findComment-422023 Share on other sites More sharing options...
Barand Posted December 23, 2007 Share Posted December 23, 2007 <?php if (isset($_POST['del'])) { $deleteList = join ("','", $_GET['del']); mysql_query ("DELETE FROM tablename WHERE id IN ('$deleteList')"); } Quote Link to comment https://forums.phpfreaks.com/topic/82973-solved-help-with-multiple-checkboxes/#findComment-422030 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.