ted_chou12 Posted January 1, 2007 Share Posted January 1, 2007 I used a javascript to select all the checkboxes at once:<input type=checkbox value=\"Check All\" onClick=\"value=check(this.form.id)\"></td>this is a bit like your email service where they let you delete all the mails at once.and this is the check boxes beside every mail messages, the number of checkboxes is not fixed.echo "<td align=center><input type=checkbox name=id value=\"". $r['id'] ."\"></td>\n";this is the php script that runs for only one checkbox:<?php if(isset($_POST['delete'])){$id = $_POST['id'];require("../mysqlconnection2.php");$privatemessages = $username.'privatemessages';$delete = mysql_query("DELETE FROM $privatemessages WHERE id='$id'");if($delete === false){echo"<p><b>Sorry, the database is temporary down, please come back later!</b></p>";}else{header("location: confirm.php?confirm=pm_delete");}}?>but what I want is for it to run however much check boxes are ticked, so you can tick all of it, and the xcript will delete all of the messages, or you can tick half of it for the script to delete the half of pms you specified(ticked).Thanks, if you dont understand what I am talking about, please feel free to reply to this thread.Ted Link to comment https://forums.phpfreaks.com/topic/32423-how-to-run-the-script-for-all-checkboxes/ Share on other sites More sharing options...
Liquix Posted January 1, 2007 Share Posted January 1, 2007 <input type=checkbox name=id value=\"". $r['id'] ."\">Remember the braces after name, name=id[]The the result will be gotten like this: [code]<?php$id_count = (is_array($_GET['id'])) ? count($_GET['id']) : 0;for($i = 0; $i < $id_count; $i++){$delete = mysql_query("DELETE FROM $privatemessages WHERE id='" . $_GET['id'][$i] . "'");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32423-how-to-run-the-script-for-all-checkboxes/#findComment-150625 Share on other sites More sharing options...
ted_chou12 Posted January 1, 2007 Author Share Posted January 1, 2007 no... it doesnt seem to work for me, should I put this:$id_count = (is_array($_GET['id'])) ? count($_GET['id']) : 0;for($i = 0; $i < $id_count; $i++){$delete = mysql_query("DELETE FROM $privatemessages WHERE id='" . $_GET['id'][$i] . "'");}in bewteen this:if(isset($_POST['delete'])){}?How about the checkboxes? I just name them like this:name=id[]?If so, wouldnt my javascript needed to be changed to this:<input type=checkbox value=\"Check All\" onClick=\"value=check(this.form.[color=red]id[][/color])\"></td>Can anyone help me please?Ted Link to comment https://forums.phpfreaks.com/topic/32423-how-to-run-the-script-for-all-checkboxes/#findComment-150769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.