i trying extract , display on web page, non 0 columns mysql database. ever column's date 0000-00-00,i dont want dispaly columns on web page.
below html code , php script respectively
<form action="search.php" method="post"> <p> <lable>enter 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 script,
<?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 * $dbname.statusinfo 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>"; ?> now getting column displayed on web page, need columns has date recorded not 0000-00-00 recorded column.
mysql table. 
output getting is

want display non 0 columns. in advance
try this:
$result = mysqli_query($conn, "select * $dbname.statusinfo soid = '$userinput1' , date_column <> '0000-00-00' ") or die(mysqli_error($conn)); although, mysql may able this:
$result = mysqli_query($conn, "select * $dbname.statusinfo soid = '$userinput1' , date_column > '0000-00-00' ") or die(mysqli_error($conn)); hope helps
edit
i can see want amended question :) unfortunately not know of way want using sql (someone may).
you outputting column headings , not outputting particular column cause them appear in wrong columns have output nothing time 0000-00-00
this how in php though. (and if have missed point again may shoot myself :))
<?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 * $dbname.statusinfo soid = '$userinput1' ") or die(mysqli_error($conn)); $arrayheadings = array( "dept" => "department", "samplerecived" => "sample recived", "molbioextraction" => "mol-bio extraction", "molbioextractionqc" => "extraction qc", "libraryprep" => "library prep", "libraryqc" => "library qc", "sequencing" => "sequencing", "datacheck" => "data check", "resequencing" => "re sequencing", "qccheck" => "qc check", "analysisstarted" => "analysis started", "analysiscompleted" => "analysis completed", "report" => "report", "outbound" => "outbound", ); ?> <style> th{ color: blue; } td{ color: black; } </style> <table border='1'> <tr> <?php foreach($arrayheadings $key => $name): ?> <th><?= $name; ?></th> <?php endforeach; ?> </tr> <tr> <?php while($row = mysqli_fetch_assoc($result)): ?> <?php foreach($arrayheadings $key => $name): ?> <?php if($row[$key] != "0000-00-00"): ?> <td><?= $row[$key]; ?></td> <?php else: ?> <td></td> <?php endif; ?> <?php endforeach; ?> <?php endwhile; ?> </tr> </table> edit
the table headings not output if field contains 0000-00-00. relies on 1 element being output @ time.
<?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 * $dbname.statusinfo soid = '$userinput1' ") or die(mysqli_error($conn)); $arrayheadings = array( "dept" => "department", "samplerecived" => "sample recived", "molbioextraction" => "mol-bio extraction", "molbioextractionqc" => "extraction qc", "libraryprep" => "library prep", "libraryqc" => "library qc", "sequencing" => "sequencing", "datacheck" => "data check", "resequencing" => "re sequencing", "qccheck" => "qc check", "analysisstarted" => "analysis started", "analysiscompleted" => "analysis completed", "report" => "report", "outbound" => "outbound", ); ?> <style> th{ color: blue; } td{ color: black; } </style> <table border='1'> <tr> <?php foreach($arrayheadings $key => $name): ?> <?php if($row[$key] != "0000-00-00"): ?> <th><?= $name; ?></th> <?php endif; ?> <?php endforeach; ?> </tr> <tr> <?php while($row = mysqli_fetch_assoc($result)): ?> <?php foreach($arrayheadings $key => $name): ?> <?php if($row[$key] != "0000-00-00"): ?> <td><?= $row[$key]; ?></td> <?php endif; ?> <?php endforeach; ?> <?php endwhile; ?> </tr> </table>
Comments
Post a Comment