nashsaint Posted May 4, 2008 Share Posted May 4, 2008 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 More sharing options...
MattDunbar Posted May 4, 2008 Share Posted May 4, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104110-solved-if-statement-inside-echo/#findComment-533001 Share on other sites More sharing options...
Bauer418 Posted May 4, 2008 Share Posted May 4, 2008 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> Link to comment https://forums.phpfreaks.com/topic/104110-solved-if-statement-inside-echo/#findComment-533007 Share on other sites More sharing options...
rhodesa Posted May 4, 2008 Share Posted May 4, 2008 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>'; Link to comment https://forums.phpfreaks.com/topic/104110-solved-if-statement-inside-echo/#findComment-533008 Share on other sites More sharing options...
nashsaint Posted May 4, 2008 Author Share Posted May 4, 2008 Thanks a lot guys for all your help. I tried your suggestions in different conditions and all work.. Thanks again. Link to comment https://forums.phpfreaks.com/topic/104110-solved-if-statement-inside-echo/#findComment-533041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.