【发布时间】:2014-06-16 08:40:13
【问题描述】:
大家好,我是 php 和 mysql 的新手。我想问一下如何将复选框的属性从未选中更改为从单个复选框中选中。对于这种情况,我正在显示来自我的数据库的查询,并且我希望有一些功能,例如电子邮件的收件箱,一旦我们选中控制复选框,该行中的所有复选框也将被选中。
提前谢谢你...
顺便说一下,这是我在 php 和 java 脚本中的代码,
<script>
$(function () {
$("#checkAll").click(function () {
if ($("#checkAll").is(':checked')) {
$(".select").prop("checked", true);
} else {
$(".select").prop("checked", false);
}
});
});
</script>
然后是php代码:
error_reporting (E_ALL ^ E_NOTICE);
if(isset($_POST['department'])){
$department=$_POST['department'];
$course=$_POST['course'];
$level=$_POST['level'];
if ($department=="0"){
echo "Please select Department!";
}else if (($department!="0")&&($course=="0")&&($level =='0')){
$query = "SELECT* FROM studaccnt WHERE dept='$department' ORDER BY fname asc";
$result = mysql_query($query,$link)
or die ("Invalid query".mysql_error());
echo "<table border=0 align=center style='table-layout:fixed'>";
echo "<tr align = center bgcolor = '#A9F5FE' >";
echo "<td width=35><input type='checkbox' name='checkAll' id='checkAll' title='select all'>
<td width=100><strong>Family Name</strong></td><td width=100><strong>Given Name</strong></td>";
echo "</td><td width=30><strong>M.I.</strong></td>";
echo "<td width=160><strong>Department</strong> </td>";
echo "<td width=100><strong>Program</strong> </td>";
echo "<td width=30><strong>Level</strong> </td>";
echo "<td width=100><strong>Contact Number</strong> </td>";
echo "<td width=300><strong>Present Address</strong> </td>";
"</tr>";
while ($row = mysql_fetch_array($result,MYSQL_BOTH))
{
$msgcode=$row["studid"];
$message=$row["fname"];
//echo "<td width=230><a href=editmsg.php?cmd=edit&msgcode=$msgcode><strong>$row[3]</strong>";
//echo "<td width=330><a href=editmsg.php?cmd=edit&msgcode=$msgcode>$row[5]";
echo "<tr class=btnav style='table-layout:fixed' bgcolor='#E0FFC1' onmouseover=style.backgroundColor='#CCFF99';
onmouseout=style.backgroundColor='#E0FFC1'>";
echo "<td width=50 align=center><input type='checkbox' name='select' value='checkbox'>";
echo "<td width=40>$row[1]";
echo "<td width=40>$row[2]";
echo "<td width=30 align=center>$row[3]";
echo "<td width=150>$row[4]";
echo "<td width=80>$row[5]";
echo "<td width=40 align=center>$row[6]";
echo "<td width=130 align=center>$row[7]";
echo "<td width=200>$row[8]";
echo "</tr>";
}
echo "</table>";
$rows = mysql_num_rows($result);
}
【问题讨论】:
-
你试过什么?
-
您需要分享您的示例 html 以及您到目前为止所尝试的内容
-
为什么会有这么多的反对票。他是 SO 的新手。给他一些时间来解释这个问题。
-
首先我尝试使用 java 脚本来完成这项工作..就像这样: 伙计们,我的道歉我不知道我可以在哪里发布我的代码在 php...:(
-
顺便说一句,我试过...