1

I need help with how to add an "if else" statement to my php script, I need the new_license_issued_date field to be null if null and not 01/01/1970 like it's currently pulling through.... please help! thanks

 <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

3 Answers 3

1

Use the ternary operator.

<td>". (is_null($row['new_license_issued_date']) 
               ? "NULL" 
               : date('d-M-Y', strtotime($row['new_license_issued_date']))) ."</td>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried:

($row['new_license_issue_date'] ? date('d-M-Y', strtotime($row['new_license_issue_date'])) : '&nbsp');

?

Comments

0

Or if it's more easy for you use this:

echo "<td>";

   if($row['new_license_issued_date'] !== NULL){
      echo date('d-M-Y', strtotime($row['new_license_issued_date']));
   } else {
      echo "&nbsp;";
   }

echo "</td>";

2 Comments

use !== instead of !=
You're right ... I have not seen ... thanks for the correction!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.