我正在从mysql到php追踪数据并在浏览中显示它。我使用了将由用户选择的复选框(列)。只会显示那些列。
仅当我选中所有复选框时才显示列,如果未选中任何一个,则表格不会出现并出现错误"未定义索引:checkboxName"。
请检查我的以下代码,该代码用于过滤特定列。
%o
答案 0 :(得分:0)
您在代码中使用了大括号Obj
,但是您没有一个转义大括号{}
来封装您的if。
要么添加这些,要么改为使用此语法:
}
关于<?php if($_POST['Date'] == 'Date'): ?>
<th style="border: 1px solid #333333; height: 20px; background: #9999E6;font-weight: bold;">Date / Hour</th>
<?php endif; ?>
<?php if($_POST['Ingress'] == 'Ingress'): ?>
<th style="border: 1px solid #333333; height: 20px; background: #9999E6;font-weight: bold;">Ingress</th>
</php endif; ?>
错误 - 请确保验证这些Undefined index
变量是否已实际设置(使用PHP isset函数)
答案 1 :(得分:0)
我认为存在语法错误。请使用小括号。
<?php if($_POST['Date'] == 'Date') { ?>
<th style="border: 1px solid #333333; height: 20px; background: #9999E6;font-weight: bold;">Date / Hour</th>
<?php } else if($_POST['Ingress'] == 'Ingress') { ?>
<th style="border: 1px solid #333333; height: 20px; background: #9999E6;font-weight: bold;">Ingress</th>
<?php } ?>
答案 2 :(得分:0)
您使代码更加复杂:
使用css文件并将样式添加到类(或th标签),链接<head>
- 标签中的css
.myClass {
border: 1px solid #333333;
height: 20px;
background: #9999E6;
font-weight: bold;
}
您的代码如下:
<?php if($_POST['Date'] == 'Date') ?>
<th class="myClass">Date / Hour</th>
<?php if($_POST['Ingress'] == 'Ingress') ?>
<th class="myClass">Ingress</th>
<?php if($_POST['Egress'] == 'Egress') ?>
<th class="myClass">Egress</th>
<?php if($_POST['Attempts'] == 'Attempts') ?>
<th class="myClass">Attempts</th>
<?php if($_POST['ASR'] == 'ASR') ?>
<th class="myClass">ASR</th>
<?php if($_POST['ACD'] == 'ACD') ?>
<th class="myClass">ACD</th>
<?php if($_POST['CER'] == 'CER') ?>
<th class="myClass">CER</th>
<?php if($_POST['TQI'] == 'TQI') ?>
<th class="myClass">TQI</th>
<?php if($_POST['min'] == 'min') ?>
<th class="myClass">Minutes</th>
你可以更进一步:
<?php
$arr = {
'Date' => 'Date / Hour',
'Ingress' => 'Ingress',
'Egress' => 'Egress',
'Attempts' => 'Attempts',
'ASR' => 'ASR',
'ACD' => 'ACD',
'CER' => 'CER',
'TQI' => 'TQI',
'min' => 'min',
};
foreach( $arr as $index => $value ) {
if (isset($_POST[ $index] && $_POST[ $index ] == $index) )
echo "<th class='myClass'>$value</th>";
}
&GT;