This question already has answers here:
How to extract only columns which has non zero values in mysql and php?
(2个答案)
4年前关闭。
我只想显示非零列,而不是显示数据库中所有为空的列。
我尝试过的HTML脚本和php脚本下面。
下面的PHP脚本
现在输出我得到的是
在上图中,它显示了没有值的所有列,但是我只需要那些具有值的列。
帮助我在代码中进行此类修改。
提前致谢。
(2个答案)
4年前关闭。
我只想显示非零列,而不是显示数据库中所有为空的列。
我尝试过的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>";
?>
现在输出我得到的是
在上图中,它显示了没有值的所有列,但是我只需要那些具有值的列。
帮助我在代码中进行此类修改。
提前致谢。
最佳答案
我很确定您前几天发布了此消息,并被告知您无法执行此操作。
如果第1列有排序日期,但第2列没有日期怎么办?
如果只有一个结果,那么您可以执行此操作。
如果所有结果在同一列中都为0,则可以执行此操作。
关于php - 如何在mysql中显示所需的列? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31513736/