如何通过php和HTML在mysql中只显示非零字段?

时间:2015-07-20 03:48:43

标签: php html mysql

enter image description here

上图是mysql数据库中的数据条目。

enter image description here

以上图片是我得到的输出,

但我需要只显示非零字段作为输出,意味着从"样本复活"列到"库qc"仅限列。

php脚本是

<?php

$userinput1 = $_POST['soid'];

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}

$result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1'  ") or die(mysqli_error
    ($conn));
echo "<p><font size= 4>SO_NUMBER:$userinput1";

echo "<table border='1'>
<tr>
<style>
th{
color: blue;
}

td{
color: black;
}
</style>

<th>Sample Recived</th>
<th>Mol-Bio Extraction</th>
<th>Extraction QC</th>
<th>Library Prep</th>
<th>Library QC</th>
<th>Sequencing</th>
<th>Data Check</th>
<th>RE Sequencing</th>
<th>QC Check</th>
<th>Analysis Started</th>
<th>Analysis Completed</th>
<th>Report</th>
<th>Outbound</th>
 </tr>";
while($row = mysqli_fetch_assoc($result))
   {
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>";
}
echo "</table>";  
?>   

2 个答案:

答案 0 :(得分:1)

在你的while循环中使用

这样的每个字段(对所有字段都这样使用):

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

答案 1 :(得分:0)

对各个字段使用类型转换运算符int()

$var = (int) $var ? $var : '';

<强>解释

空白日期0000-00-00 00:00:00始终返回空白/空白0

在上面的代码中,它将返回0因此,它不会显示空白/空白日期。

仅显示具有某些非零值的日期。