gpt4 book ai didi

php - 使用 php 检查表格单元格是否为空

转载 作者:行者123 更新时间:2023-11-29 02:52:47 24 4
gpt4 key购买 nike

我可以使用 PHP 检查表格单元格是否为空吗?我正在使用 for 循环做一个报告,当该部分没有填满时它不会显示表格,所以它使表格看起来很奇怪。 so if they didn't filled one of the section, it will display in this way.

    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>";

enter image description here

最佳答案

试试这段代码(已测试):

    $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>";
}
}

关于php - 使用 php 检查表格单元格是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33952080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com