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

时间:2022-09-15 16:34:45

can I check table cell is empty or not by using PHP? I am doing a report using for loop, when the section didn't filled up it will not display the table so it made the table looks weird.使用php检查表格单元格是否为空

我可以使用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>";

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

1 个解决方案

#1


1  

Try this code (tested):

试试这个代码(测试过):

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

#1


1  

Try this code (tested):

试试这个代码(测试过):

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