Jump to content

[SOLVED] IF statement inside Echo <table>


nashsaint

Recommended Posts

Hi again,

 

I have a problem inserting IF statement inside echo command.  I want to check the Status field whether Complete of Not.  If complete, I want it to be clickable to point to other link.

 

Here's my code.

echo '<tr bgcolor="' . $bg . '">
         <td align="left">' . $row['job_no'] . '
<td align="left">' . $row['model_no'] . '</td>
        <td align="left">' . $row['firmware'] . '</td>
        <td align="center">' . $row['dr'] . '</td>
        <td align="center">' . $row['ds'] . '</td>
        <td align="center">' . $row['dc'] . '</td>

         // I want to insert IF statement here to check for status
        // So that is status='Complete', Status url link will be activated 
       // If Status is now 'Complete' then no link.

        <td align="left"><b>' . $row['status'] . '</b> </td>
</tr>

 

 

Many Thanks.

Link to comment
https://forums.phpfreaks.com/topic/104110-solved-if-statement-inside-echo/
Share on other sites

Hi again,

 

I have a problem inserting IF statement inside echo command.  I want to check the Status field whether Complete of Not.  If complete, I want it to be clickable to point to other link.

 

Here's my code.

echo '<tr bgcolor="' . $bg . '">
         <td align="left">' . $row['job_no'] . '
<td align="left">' . $row['model_no'] . '</td>
        <td align="left">' . $row['firmware'] . '</td>
        <td align="center">' . $row['dr'] . '</td>
        <td align="center">' . $row['ds'] . '</td>
        <td align="center">' . $row['dc'] . '</td>

         // I want to insert IF statement here to check for status
        // So that is status='Complete', Status url link will be activated 
       // If Status is now 'Complete' then no link.

        <td align="left"><b>' . $row['status'] . '</b> </td>
</tr>

 

 

Many Thanks.

 

Place the IF statement before and have multiple echos depending on which if the condition is met or not.

That'd be ugly.  You could just do

 

	echo '<tr bgcolor="' . $bg . '">
         <td align="left">' . $row['job_no'] . '
<td align="left">' . $row['model_no'] . '</td>
        <td align="left">' . $row['firmware'] . '</td>
        <td align="center">' . $row['dr'] . '</td>
        <td align="center">' . $row['ds'] . '</td>
        <td align="center">' . $row['dc'] . '</td>

        <td align="left"><b>' . ($row['status'] == 'Complete' ? "link here" : "whatever you want if it isn't complete") . '</b> </td>
</tr>

Right, just stop the echo, do the IF, then start again:

 

<?php
echo '<tr bgcolor="' . $bg . '">
         <td align="left">' . $row['job_no'] . '
<td align="left">' . $row['model_no'] . '</td>
        <td align="left">' . $row['firmware'] . '</td>
        <td align="center">' . $row['dr'] . '</td>
        <td align="center">' . $row['ds'] . '</td>
        <td align="center">' . $row['dc'] . '</td>';
        if($row['status'] == 'Complete'){
          echo '<td align="left"><b><a href="some_url.php">' . $row['status'] . '</a></b> </td>';
        }else{
          echo '<td align="left"><b>' . $row['status'] . '</b> </td>';
echo '</tr>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.