Reputation: 149
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.
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>";
Upvotes: 2
Views: 1811
Reputation: 538
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>";
}
}
Upvotes: 1