如何在mysql中显示所需的列?

时间:2015-07-20 10:06:37

标签: php html mysql web

我想只显示非零列,而不是显示数据库中所有空列的列。

我尝试过的HTML脚本和PHP脚本。

<form action="search.php" method="post">
<p>
<lable>ENTER SO NUMBER</lable>
<input type="text"  name="soid" id="soid" >
</p>



<p><button><img src="http://icons.iconarchive.com/icons/harwen/pleasant/256/Search-icon.png"  height="50" />SEARCH</button></p>

下面的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'] == '0000-00-00' ? '' :       $row['samplerecived']) . "</td>";

echo "<td>" . ($row['molbioextraction'] == '0000-00-00' ? '' : $row['molbioextraction']) . "</td>";
echo "<td>" . ($row['molbioextractionqc'] == '0000-00-00' ? '' : $row['molbioextractionqc']) . "</td>";
echo "<td>" . ($row['libraryprep'] == '0000-00-00' ? '' : $row['libraryprep']) . "</td>";
echo "<td>" . ($row['libraryqc'] == '0000-00-00' ? '' : $row['libraryqc']) . "</td>";
echo "<td>" . ($row['sequencing'] == '0000-00-00' ? '' : $row['sequencing']) . "</td>";
echo "<td>" . ($row['datacheck'] == '0000-00-00' ? '' : $row['datacheck']) . "</td>";
echo "<td>" . ($row['resequencing'] == '0000-00-00' ? '' : $row['resequencing']) . "</td>";
echo "<td>" . ($row['qccheck'] == '0000-00-00' ? '' : $row['qccheck']) . "</td>";
echo "<td>" . ($row['analysisstarted'] == '0000-00-00' ? '' : $row['analysisstarted']) . "</td>";
echo "<td>" . ($row['analysiscompleted'] == '0000-00-00' ? '' : $row['analysiscompleted']) . "</td>";
echo "<td>" . ($row['report'] == '0000-00-00' ? '' : $row['report']) . "</td>";
echo "<td>" . ($row['outbound'] == '0000-00-00' ? '' : $row['outbound']) . "</td>";


   echo "</tr>";
   }
   echo "</table>";
?>  

现在输出我得到的是 enter image description here

在上图中,它显示所有没有值的列,但我只需要那些有值的列 帮我在代码中做这样的修改 提前谢谢。

2 个答案:

答案 0 :(得分:0)

我很确定你前几天发布了这封信,并解释说你不能这样做。

如果第1列有排序日期,但第2列没有?

,该怎么办?

如果只有一个结果,那么你可以这样做。 如果所有结果在同一列中都有0,则可以执行此操作。

答案 1 :(得分:0)

if(!empty($row['samplerecived']) && !empty($row['molbioextraction']) && !empty($row['molbioextractionqc']) && !empty($row['libraryprep']) && !empty($row['libraryqc']) && !empty($row['sequencing']) && !empty($row['datacheck']) && !empty($row['resequencing']) && !empty($row['qccheck']) && !empty($row['analysisstarted']) && !empty($row['analysiscompleted']) && !empty($row['report']) && !empty($row['outbound'])) {
    echo "<td>" . ($row['samplerecived'] == '0000-00-00' ? '' :       $row['samplerecived']) . "</td>";
    echo "<td>" . ($row['molbioextraction'] == '0000-00-00' ? '' : $row['molbioextraction']) . "</td>";
    echo "<td>" . ($row['molbioextractionqc'] == '0000-00-00' ? '' : $row['molbioextractionqc']) . "</td>";
    echo "<td>" . ($row['libraryprep'] == '0000-00-00' ? '' : $row['libraryprep']) . "</td>";
    echo "<td>" . ($row['libraryqc'] == '0000-00-00' ? '' : $row['libraryqc']) . "</td>";
    echo "<td>" . ($row['sequencing'] == '0000-00-00' ? '' : $row['sequencing']) . "</td>";
    echo "<td>" . ($row['datacheck'] == '0000-00-00' ? '' : $row['datacheck']) . "</td>";
    echo "<td>" . ($row['resequencing'] == '0000-00-00' ? '' : $row['resequencing']) . "</td>";
    echo "<td>" . ($row['qccheck'] == '0000-00-00' ? '' : $row['qccheck']) . "</td>";
    echo "<td>" . ($row['analysisstarted'] == '0000-00-00' ? '' : $row['analysisstarted']) . "</td>";
    echo "<td>" . ($row['analysiscompleted'] == '0000-00-00' ? '' : $row['analysiscompleted']) . "</td>";
    echo "<td>" . ($row['report'] == '0000-00-00' ? '' : $row['report']) . "</td>";
    echo "<td>" . ($row['outbound'] == '0000-00-00' ? '' : $row['outbound']) . "</td>";
}