我需要有关如何在我的php脚本中添加“if else”语句的帮助,我需要new_license_issued_date
字段为null,如果为null,而不是01/01/1970
,就像它正在通过... 。 请帮忙!谢谢
<table cellpadding='0' cellspacing='0' border='0' class='display' id='table' width='100%'>
<thead>
<tr>
<th>Emp Code</th>
<th width='130'>Emp Name</th>
<th width=100>Manager</th>
<th width=150>Business Unit</th>
<th width=240>Training Course Name</th>
<th width=65>Issued Date</th>
<th width=65>Expiry Date</th>
<th width=100>Cert Number</th>
</tr>
</thead>
<tbody>
<?php
//display the results
while($row = mssql_fetch_array($result))
{
echo "<tr>
<td width=40>" . $row['Emp Code'] . "</td>
<td>". $row['new_EmployeeName'] . "</td>
<td>". $row['Manager'] . "</td>
<td>". $row['BusinessUnit'] . "</td>
<td>". $row['new_TrainingCourseLookName'] . "</td>
<td>". date('d-M-Y', strtotime($row['new_license_issued_date'])) . "</td>
<td>". date('d-M-Y', strtotime($row['new_license_expiry_date'])) . "</td>
<td>". $row['new_license_no'] . "</td>
</tr>";
}
echo "</tbody>
</table>
<br>
<p><a href='index.php'><< Back to Portal</p>
</div>";
//close the connection
mssql_close();
?>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" language="javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="assets/js/jquery.dataTables.js"> </script>
<script type='text/javascript' charset='utf-8'>
$(document).ready(function() {
$('table').dataTable();
} );
</script>
</body>
</html>
答案 0 :(得分:1)
使用三元运算符。
<td>". (is_null($row['new_license_issued_date'])
? "NULL"
: date('d-M-Y', strtotime($row['new_license_issued_date']))) ."</td>
答案 1 :(得分:0)
你试过了吗?
($row['new_license_issue_date'] ? date('d-M-Y', strtotime($row['new_license_issue_date'])) : ' ');
答案 2 :(得分:0)
或者如果您更容易使用它:
echo "<td>";
if($row['new_license_issued_date'] !== NULL){
echo date('d-M-Y', strtotime($row['new_license_issued_date']));
} else {
echo " ";
}
echo "</td>";