How To Display Only Non Zero Fields In Mysql Through Php And Html?
Above image is the entry of data in mysql database. Above image was the output what i am getting is, But i need to display only non zero fields as the output that means from
Solution 1:
inside your while loop use for each field like this (use like this for all fields):
while($row = mysqli_fetch_assoc($result))
{
if($row['samplerecived']=="0000-00-00") $row['samplerecived']="";
echo"<tr>";
echo"<br />";
echo"Department:".$row['dept'] ;
echo"<td>" . $row['samplerecived'] . "</td>";
echo"<td>" . $row['molbioextraction'] . "</td>";
echo"<td>" . $row['molbioextractionqc'] . "</td>";
echo"<td>" . $row['libraryprep'] . "</td>";
echo"<td>" . $row['libraryqc'] . "</td>";
echo"<td>" . $row['sequencing'] . "</td>";
echo"<td>" . $row['datacheck'] . "</td>";
echo"<td>" . $row['resequencing'] . "</td>";
echo"<td>" . $row['qccheck'] . "</td>";
echo"<td>" . $row['analysisstarted'] . "</td>";
echo"<td>" . $row['analysiscompleted'] . "</td>";
echo"<td>" . $row['report'] . "</td>";
echo"<td>" . $row['outbound'] . "</td>";
echo"</tr>";
}
Solution 2:
Use typecasting operator int()
for the respective fields.
$var = (int) $var ? $var : '';
Explanation:
An empty date 0000-00-00 00:00:00
always return 0
which is blank/empty.
In above code, it will return 0
hence, it will not display blank/empty date.
Only dates with some non-zero values will be displayed.
Post a Comment for "How To Display Only Non Zero Fields In Mysql Through Php And Html?"