coolphpdude Posted June 25, 2008 Share Posted June 25, 2008 I started a post off a few weeks ago about this, but i have left it, avoided it, and put it to the back of my list of jobs because i wasn't having much luck with it. So any help would be appreciated. i think this will be an easy one for you lot but i just can't seem to get my head around it. I got a message database on my project. So a user receives messages from other user's just like an email system. Currently i have a delete button next to each message as it is output from the database using a while loop. Now the propblem with this is, if you have got 40 messages you have to click delete 40 times. I want it so that theres a tick box next to each message so u can mark the messages you would like to delete and click a single delete button at the top to delete all of the marked messages. Is this easy? most email messaging systems have it so i suppose its do able, i just dont know how. Also could i place a tick box at the so the user could click this and it would mark all messages on this page?? what i've got so far is with the help of jesushax which i am very grateful of. I'll post the code below... <?php session_start(); switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])){ foreach($_POST['checkbox'] as $message){ mysql_query("DELETE FROM memos WHERE message_id='$message'") or die(mysql_error()); } } //echo 'records deleted'; //break; default: echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?action=delete">'; echo "<table width='100%' border='2' bordercolor='#cccccc' style='border-collapse: collapse' cellpadding='5' align=center >\n"; echo "<tr><th>Subject</th><th>Sender</th><th>Delete</th></tr>\n"; while ($memos = mysql_fetch_array($memos)) { printf("<td>%s</td>\n", $memos["memo_subject"]); printf("<td>%s</td>\n", $my_message_row["message_sender"]); printf("<td align='center' cellpadding='10' width='60'><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$row['recordID']." '></td></tr>"); } echo "</table>\n"; echo '<tr><td colspan="3"><input type="submit" value="Delete these records" />'."\n"; echo "</form>"; ?> Cheers Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 25, 2008 Share Posted June 25, 2008 The code you have looks like it's most of the way there. What exactly isn't working? What have you done to try and troubleshoot it? Do you understand the concepts behind the code the other person helped you with? Because once you understand the concept the steps for troubleshooting are always the same: 1) Know what data to expect 2) Look at what you have Are 1 and 2 the same? Yes - Your code works (assuming you got #1 correct). No - What did you get that you didn't expect and why? Quote Link to comment Share on other sites More sharing options...
coolphpdude Posted June 26, 2008 Author Share Posted June 26, 2008 Hi sorry for not replying sooner, i got pulled away from working on this. So far i played about with the positioning of the code as when we originally started it was producing lots of errors. Now, theres no errors but when you tick a box and cclick the delete button, the page kind of refreshes but nothing is deleted... Quote Link to comment Share on other sites More sharing options...
zenag Posted June 26, 2008 Share Posted June 26, 2008 u have not mentioned ....$row['recordID'] change it as $memos['recordID'] printf("<td align='center' cellpadding='10' width='60'><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$memos['recordID']." '></td></tr>"); } echo "</table>\n"; Quote Link to comment Share on other sites More sharing options...
coolphpdude Posted June 26, 2008 Author Share Posted June 26, 2008 ahhh!! That obvious!! i'll give it ago! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 When I do these types of things for my stuff, I need to give each input field a unique name. I'm not sure what you're doing by calling it "checkbox[]', I would suggest "cb$row[recordID]" as to give each a unique name then step through each using current() and next() Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 26, 2008 Share Posted June 26, 2008 @dannyb785 He's calling it checkbox[] to place them into a numerically indexed array named $checkbox. He's distinguishing the IDs in the value attribute of the checkbox. Basically, the method he has should work fine if he can sort things out on the back end. Quote Link to comment 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.