【发布时间】:2015-07-17 11:33:32
【问题描述】:
我正在尝试提取并显示在网页上,只有来自 mysql 数据库的非零列。哪一列的日期是 0000-00-00,我不想在网页上显示这些列。
下面分别是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>
</form>
</html>
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>";
?>
现在我正在网页上显示所有列,我只需要那些记录日期而不是 0000-00-00 记录列的列。
这是 mysql 表。
我得到的输出是
我只想显示非零列。
提前致谢
【问题讨论】:
-
只选择列不工作的地方?
where `date` <> '0000-00-00'另请注意,您可以使用此代码进行 SQL 注入。您应该使用参数化查询。 php.net/manual/en/mysqli.quickstart.prepared-statements.php -
您是否尝试过在您的 MYSQL 中添加 WHERE 子句,例如
WHERE date_recorded != '0000-00-00'最重要的是,作为您希望在 SQL 语句中使用参数的提示。现在你对 SQL 注入攻击非常开放。尝试使用 PDO -
@Catharsis
mysqli支持准备好的语句,OP 只是没有使用它们。 -
@chris85 是的,你是对的,我在发表评论之前没有检查过 :)
-
可以这样做吗??