我试图为表格中的每个单元格添加复选框。
如果$columns['mything$record']
等于1,我想要一个选中的复选框显示。
如果$columns['mything$record']
等于0,我想要一个空白复选框显示。我创建了以下可以查看的语句,但是他们没有在每个表格单元格中放置一个具有相应值的复选框,页面顶部只显示一个空白复选框。
如何根据单元格值在每个单元格中放置已选中和取消选中的复选框?
[![截图] [1] [1]
$stmt = $sql->prepare("SELECT record,shortName FROM dms
where dms.isInactive=0
ORDER BY lastName asc, firstName asc");
$stmt->execute();
$shortNameArray=array();
while ($row = $stmt->fetch()) {
// print_r($row);
$shortNameArray[$row['record']]=$row['shortName'];
}
//print_r($shortNameArray);
$columns = array(
1 => array(
"selectFieldName" => "nrs.record nrRecord",
"resultFieldName" => "nrRecord",
"headerName" => "NT#",
"defaultSortOrder" => -1,
),
array(
"selectFieldName" => "nrs.title",
"resultFieldName" => "title",
"headerName" => "Title",
"defaultSortOrder" => 1,
),
);
$selectedColumnNumbers = array(1,2,3);
$counter=4;
foreach($shortNameArray as $record=>$name){
if($record>0){
$columns[]=array(
"selectFieldName" => "CASE WHEN $record IN (GROUP_CONCAT(dm_nr_links.dmRecord)) THEN 1 ELSE 0 END mything$record",
"resultFieldName" => "mything$record",
"headerName" => "$name",
"defaultSortOrder" => 1,
);
$selectedColumnNumbers[]=$counter;
$counter++;
if ($columns['mything$record'] == 1) {
echo "<input type='checkbox' name='PLJan' checked='checked' />";
}
if ($columns['mything$record'] == 0) {
echo "<input type='checkbox' name='JLFeb' />";
}
}
}
$selectedColumns = array();
$selectedFields = array(); // contains all the fields to be selected
foreach ($selectedColumnNumbers as $columnNumber){
$selectedColumns[$columnNumber] = $columns[$columnNumber];
if (strlen($columns[$columnNumber]["selectFieldName"]) > 0)
$selectedFields[] = $columns[$columnNumber]["selectFieldName"];
}
$selectedFields = array_unique($selectedFields); // Remove all duplicate fields for selection
///// Process Filter Cookies
$filterWhereString = "";
$filterBindValues = array();
for ($c=1; $c<=5; $c++) {
if (isset($_COOKIE["nrsfl$c"])
&& isset($_COOKIE["nrsfl$c"."Op"])
&& isset($_COOKIE["nrsfl$c"."Val"])
&& strlen($_COOKIE["nrsfl$c"."Val"]) > 0
) {
$columnNumber = $_COOKIE["nrsfl$c"];
$filterOperator = $_COOKIE["nrsfl$c"."Op"];
$filterValue = $_COOKIE["nrsfl$c"."Val"];
if (isset($columns[$columnNumber])){
if ($c >= 2) {
$lastC = ($c-1);
if (strlen($filterWhereString) > 0) // If string exists, add conjunction
{
if (isset($_COOKIE["nrsfl$lastC"."C"])){
$conSelect = $_COOKIE["nrsfl$lastC"."C"];
} else $conSelect = 1;
if ($conSelect == 1) $conjunction = "AND";
else $conjunction = "OR";
$filterWhereString .= "$conjunction ";
}
}
$column = $columns[$columnNumber];
$fieldName = $column['resultFieldName'];
$filterWhereString .= "$fieldName ";
switch ($filterOperator) {
case 1:
$operator = "=";
break;
case 2:
$operator = "LIKE";
break;
case 3:
$operator = ">=";
break;
case 4:
$operator = "<=";
break;
case 5:
$operator = ">";
break;
case 6:
$operator = "<";
break;
case 8:
$operator = "NOT LIKE";
break;
default:
$operator = "!=";
}
if ((strcmp($operator, "NOT LIKE") == 0) ||(strcmp($operator, "LIKE") == 0)) $filterField = "CONCAT('%',:filter".$c.",'%')";
else $filterField = ":filter$c";
$filterWhereString .= "$operator $filterField ";
if (substr_compare($fieldName, "date", 0, 4) == 0) { // Convert dates
$filterValue = strtotime($filterValue);
$filterValue = date("Y-m-d",$filterValue);
}
if ($fieldName=="isRestricted") { // Convert binaries
if(strtolower($filterValue)=='y')$filterValue="1";
if(strtolower($filterValue)=='n')$filterValue="0";
}
$filterBindValues[":filter$c"] = $filterValue;
}
}
}
/////
&GT;
答案 0 :(得分:0)
替换您的代码行
echo "<input type='checkbox' name='PLJan' ";
echo "checked='checked'";
与
echo "<input type='checkbox' name='PLJan' checked='checked' />";
echo "<input type='checkbox' name='JLFeb' ";
与
echo "<input type='checkbox' name='JLFeb' />";