我可以使用PHP检查表格单元格是否为空? 我正在使用for循环进行报告,当该部分没有填满时,它将不会显示该表,因此它使表格看起来很奇怪。
echo"<table width='100%' border='3' class='table table-striped' style='font-size:12px;'>";
for($i=0;$i<$num_results;$i++){
$row = $result->fetch_array();
$totalsum=0;
$query5 = "SELECT * FROM outlet_type_location WHERE id = '$row[outlet_type_location_id]'";
$result5 = $db->query($query5);
$row5 = $result5->fetch_array();
echo"<tr>";
echo"<th width='15%'>".$row5['location']."</th>";
$query2 = "SELECT section_mark FROM audit_section_section_mark WHERE audit_section_no = '$row[audit_no]'";
$result2 = $db->query($query2);
$num_results2 = $result2->num_rows;
for($j=0;$j<$num_results2;$j++){
$row2 = $result2->fetch_array();
$ss_mark = $row2['section_mark'];
echo"<td width='10%' align='center' id='my_cell'>$ss_mark</td>";
}
//listing total result
echo"<td width='10%' align='center'>";
if($totalsum < 70){
echo"<font color='red'><b>$totalsum/100</b></font>";
}else if($totalsum >= 80){
echo"<font color='#00CC33'><b>$totalsum/100</b></font>";
}
else{
echo"<font><b>$totalsum/100</b></font>";
}
echo"</td>";
echo"</tr>";
}
echo"</table>";
答案 0 :(得分:1)
试试这段代码(已测试):
$query2 = "SELECT section_mark FROM audit_section_section_mark WHERE audit_section_no = '$row[audit_no]'";
$result2 = $db->query($query2);
$num_results2 = $result2->num_rows;
if($num_results2 != 0){
for($j=0;$j<$num_results1;$j++){
$row2 = $result2->fetch_array();
if(isset($row2['section_mark'])){
echo "<td width='10%' align='center' id='my_cell'>" . $row2['section_mark']. "</td>";
}else{
echo "<td width='10%' align='center' id='my_cell'>-</td>";
}
}
}
else{
for($j=0;$j<$num_results1;$j++){
echo"<td width='10%' align='center' id='my_cell'></td>";
}
}