Russia Posted August 25, 2009 Share Posted August 25, 2009 I currently have this script, I need it to check when I click the checkall button. Hm... now for some reason the select all button isnt working... Current code: <?php error_reporting(E_ALL); require("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM persons WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting persons! Query: $query<br />Error: ".mysql_error()); } } } $result = mysql_query("SELECT * FROM persons"); // Check how many rows it found if(mysql_num_rows($result) > 0){ echo "<table id=\"mytable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Delete</th> <th align=\"center\" scope=\"col\">First Name</th> <th align=\"center\" scope=\"col\">Last Name</th> <th align=\"center\" scope=\"col\">High Scores</th> <th align=\"center\" scope=\"col\">Date of Entry</th> <th align=\"center\" scope=\"col\">IP Address</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; while($row = mysql_fetch_array($result)) { echo "<tr align=\"center\">"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>'; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td><a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Check HighScores</a></td>"; echo "<td>" . $row['AddedDate'] . "</td>"; echo "<td>" . $row['Ip'] . "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>"; } else{ // No rows were found ... echo "No Registered Members"; echo "</tbody>"; echo "</table>"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
merck_delmoro Posted August 25, 2009 Share Posted August 25, 2009 I have answer that before here is the your last post that I answer that question http://www.phpfreaks.com/forums/index.php/topic,266488.0.html and by the way. again you forgot to make a JavaScript function named checkall and uncheckall Quote Link to comment Share on other sites More sharing options...
Russia Posted August 25, 2009 Author Share Posted August 25, 2009 <script type="text/javascript"> function checkall(chek) { for (i = 0; i < chek.length; i++) chek[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(chek) { for (i = 0; i < chek.length; i++) chek[i].checked = false; } </script> Soz Forgot To add. Quote Link to comment Share on other sites More sharing options...
merck_delmoro Posted August 25, 2009 Share Posted August 25, 2009 Any more questions??? Quote Link to comment Share on other sites More sharing options...
Russia Posted August 25, 2009 Author Share Posted August 25, 2009 Ye it wont select all when I click the button. Check the code to see if I did anything wrong. Quote Link to comment Share on other sites More sharing options...
merck_delmoro Posted August 25, 2009 Share Posted August 25, 2009 I have tested the code it check all the checkboxes when I click button named "SELECT ALL" try your code from your post yesterday here is the link http://www.phpfreaks.com/forums/index.php/topic,266488.0.html Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 25, 2009 Share Posted August 25, 2009 How does this code, match your JavaScript button code, mate please explain russia. <script type="text/javascript"> function checkall(chek) { for (i = 0; i < chek.length; i++) chek[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(chek) { for (i = 0; i < chek.length; i++) chek[i].checked = false; } </script> Quote Link to comment Share on other sites More sharing options...
Russia Posted August 25, 2009 Author Share Posted August 25, 2009 I tried my best. What are the errors? What should be changed. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 25, 2009 Share Posted August 25, 2009 merck_delmoro has shown you ever think needed, can you read please? there also a link provided to see how it works from merck_delmoro now you no why learning java script is far better then copy and pasting . Something more important then that in your code, u use the ip address of the user, well it not the correct way for security issues use the user's id .... example, i can set my own ip, if i am behind a proxy server, but it not mine is it? never rely on users ip address ever. Quote Link to comment Share on other sites More sharing options...
Russia Posted August 25, 2009 Author Share Posted August 25, 2009 Its alright... I might remove that feature... Quote Link to comment Share on other sites More sharing options...
merck_delmoro Posted August 25, 2009 Share Posted August 25, 2009 there are no errors it checks all the check boxes when I click it are you sure you are clicking the right button??? <?php error_reporting(E_ALL); require("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM persons WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting persons! Query: $query<br />Error: ".mysql_error()); } } } $result = mysql_query("SELECT * FROM persons"); // Check how many rows it found if(mysql_num_rows($result) > 0){ echo "<table id=\"mytable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Delete</th> <th align=\"center\" scope=\"col\">First Name</th> <th align=\"center\" scope=\"col\">Last Name</th> <th align=\"center\" scope=\"col\">High Scores</th> <th align=\"center\" scope=\"col\">Date of Entry</th> <th align=\"center\" scope=\"col\">IP Address</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; while($row = mysql_fetch_array($result)) { echo "<tr align=\"center\">"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>'; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td><a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Check HighScores</a></td>"; echo "<td>" . $row['AddedDate'] . "</td>"; echo "<td>" . $row['Ip'] . "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>"; } else{ // No rows were found ... echo "No Registered Members"; echo "</tbody>"; echo "</table>"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 25, 2009 Share Posted August 25, 2009 is JavaScript switched on on the browser settings? Quote Link to comment Share on other sites More sharing options...
Russia Posted August 26, 2009 Author Share Posted August 26, 2009 Fixed, I missed a \ when I was editing it, so it was calling it as a php variable or something. 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.