Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过php和HTML在mysql中只显示非零字段?_Php_Html_Mysql - Fatal编程技术网

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

如何通过php和HTML在mysql中只显示非零字段?,php,html,mysql,Php,Html,Mysql,上图是mysql数据库中的数据条目 上图是我得到的输出 但我只需要显示非零字段作为输出,这意味着仅从“样本恢复”列显示到“库qc”列 php脚本是 <?php $userinput1 = $_POST['soid']; $servername = "localhost"; $username = "root"; $password = ""; $dbname = "status"; $conn = new mysqli($servername, $username, $passwo

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

上图是我得到的输出

但我只需要显示非零字段作为输出,这意味着仅从“样本恢复”列显示到“库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>";  
?>   

在while循环中,对每个字段使用如下方式(对所有字段使用如下方式):

while($row=mysqli\u fetch\u assoc($result))
{
如果($row['samplerecived']==“0000-00-00”)$row['samplerecived']==”;
回声“;
回声“
”; echo“部门:.”行['dept']; 回显“$row['samplerecived']”; echo“$row['molboExtraction']”; echo“$row['MolboExtractionQC']”; 回显“$row['libraryprep']”; 回显“$row['libraryqc']”; 回显“$row['sequencing']”; 回显“$row['datacheck']”; 回显“$row['resquenting']”; 回显“$row['qccheck']”; 回显“$row['analysisstarted']”; 回显“$row['analysiscompleted']”; 回显“$row['report']”; 回显“$row['outbound']”; 回声“; }
对各个字段使用类型转换操作符
int()

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

空日期
0000-00-00 00:00:00
始终返回为空的
0

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


只显示一些非零值的日期。

如果字段=0000-00-00不回显其日期字段,如何只回显日期字段??应使用if条件或三元运算符!对不起,我没有得到你的分数!!!如果可能,您能简单解释一下吗?如果字段的值为0000-00-00,那么该字段将等于mysqli_查询中查询下面设置的空白(“”),选择soid,dept,if(sampleRecieved='0000-00-00'或sampleRecieved=''',sampleRecieved',,sampleRecieved)作为sampleRecieved,if(molboExtraction='0000-00-00'或molboExtraction='',molboExtraction)作为molboExtraction,如果(MolboExtraction QC='0000-00-00'或MolboExtraction QC='',MolboExtraction QC)作为MolboExtraction QC,如果(LibraryQC='0000-00-00'或LibraryQC=''',LibraryQC)作为LibraryQC,如果(Sequnting='0000-00-00'或Sequnting=''',Sequnting)作为Sequnting,如果(datacheck='0000-00-00'或datacheck='',datacheck作为datacheck作为datacheck,来自$dbname.statusinfo,其中soid='$userinput1'
$var = (int) $var ? $var : '';