ElChoco Posted August 11, 2006 Share Posted August 11, 2006 I would like to 'hide' selections based on ticked checkboxes. I'm running into a bit of trouble though. I have the select all, de-select all buttons working but when I try to change the table for all those clicked it fails. ??? It hurts my brains, all of them. Thanks[code]<?PHPsession_start(); // This connects to the existing session$username = $_SESSION['username'];$password = $_SESSION['password'];if (!isset($username) || !isset($password)) { header( "Location: http://www.bedwettingstore.com/login.php?login=fail" );}/*********************************** The Welcome Table and logout ***********************************/?> <table width="100%"><tr><td align="left">Welcome <font face="Verdana, Arial, Helvetica, sans-serif" size="3"><b><?=$username?></b></font></td><td align="right"><a href="logout.php">Log Out</a></td></tr></table><br /><br /><?PHP/******************** DB Variables ********************/$dbhost = "###.###.###.###"; $dbuser = "username"; $dbpass = "password"; $dbname = "dbname"; /************************ Connect to DB ************************/ global $link;$link = mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db("$dbname",$link)or die( "Unable to select database".mysql_error()); // Get All Fields from table$query="SELECT * FROM searchresults where view=\"1\"";$result=mysql_query($query);// Count number of (different) data$num = mysql_numrows($result);//Close Connection//mysql_close();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript" language="javascript">/*********************************//*** CHECK or UnCHECK all boxes **//*********************************/<!-- var form='checkboxForm' //Give the form name herefunction SetChecked(val,chkName) {dml=document.forms[form];len = dml.elements.length;var k=0;for( k=0 ; k<len ; k++) {if (dml.elements[k].name==chkName) {dml.elements[k].checked=val;}}}function deleteRecords(checkbox){ <?php if (isset($_POST["checked"])) { foreach ($_POST["checked"] as $checkbox) { $sql="update searchresults set view='0'"; mysql_query($sql); } } ?>}// --></script></head><body><a href="javascript:SetChecked(1, 'checked[]')">Check All</a> <a href="javascript:SetChecked(0, 'checked[]')">Un-Check All</a> <a href="javascript:deleteRecords('checked[]')">Delete Records</a><form name="checkboxForm" method="post" action="#" onSubmit="return ValidateForm(this, 'checked')"><table border="1"><tr><td align="center"> </td><td align="center" width="12">#</td><td align="center">Date & Time</td><td align="center">Search Query</td><td align="center">Page</td></tr><?$i=0;while ($i < $num) {$id=mysql_result($result,$i,"count");$datetime=mysql_result($result,$i,"datetime");$search=mysql_result($result,$i,"search");$page=mysql_result($result,$i,"page");?><tr><td><input type="checkbox" name="checked[]" value="<?=$id?>" > <td align=\"center\"><?=$id?></td><td align=\"center\"><?=$datetime?></td><td align="center"><?=$search?></td><td align="center"><?=$page?></td></tr><?PHP$i++;}?></table></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/17236-deleting-ticked-checkboxes-and-it-hurts/ Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 <?php if (isset($_POST["checked"])) { foreach ($_POST["checked"] as $checkbox) { $sql="update searchresults set view='0'"; mysql_query($sql); } } ?>needs to be<?php if (isset($_POST["checked"])) { foreach ($_POST["checked"] as $checkbox) { $sql="update searchresults set view='0' WHERE count = '$checkbox'"; mysql_query($sql); } } ?>because otherwise u will be setting the whole table to view=0Regardsliam Link to comment https://forums.phpfreaks.com/topic/17236-deleting-ticked-checkboxes-and-it-hurts/#findComment-73058 Share on other sites More sharing options...
ElChoco Posted August 11, 2006 Author Share Posted August 11, 2006 Oops, yeah. Thanks.What I know, is that the function is being called, but $checkbox isn't set correctly. If I put an echo in there nothing prints.[code] <?php if (isset($_POST["checked"])) { foreach ($_POST["checked"] as $checkbox) { echo '$checkbox'; $sql="update searchresults set view='0' WHERE count = '$checkbox'"; mysql_query($sql); } } ?>[/code]Do I have my array messed up?Thanks again. This is a great forum. Link to comment https://forums.phpfreaks.com/topic/17236-deleting-ticked-checkboxes-and-it-hurts/#findComment-73063 Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 just looked at your code again and are you trying to set a javascript function to do php? if so then you can't as the php is parsed as soon as u access the site and wont be stored in any clientside language..Hope you understand thisRegardsliam Link to comment https://forums.phpfreaks.com/topic/17236-deleting-ticked-checkboxes-and-it-hurts/#findComment-73069 Share on other sites More sharing options...
ElChoco Posted August 11, 2006 Author Share Posted August 11, 2006 OH! well duh, I feel just stupid. ::) I've been looking at this for much too long to not have noticed that. Thank you. Everything works now, it submits to another page.I do love this forum! ;D Link to comment https://forums.phpfreaks.com/topic/17236-deleting-ticked-checkboxes-and-it-hurts/#findComment-73091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.