Mr Chris Posted July 11, 2007 Share Posted July 11, 2007 Hi All, I’m running a while query on a table: <? $n=1; while($result = mysql_fetch_assoc($query)) { // Set the BG $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); ?> <tr> <td bgcolor="<?php echo $bg; ?>"><?php echo $result['m_date']; ?></td> <td bgcolor="<?php echo $bg; ?>"><?php echo $result['home_team']; ?></td> <td bgcolor="<?php echo $bg; ?>"><?php echo $result['team_one_score']; ?> - <?php echo $result['team_two_score']; ?></td> <td bgcolor="<?php echo $bg; ?>"><?php echo $result['away_team']; ?></td> <td bgcolor="<?php echo $bg; ?>"><?php echo $result['competition']; ?></td> <td bgcolor="<?php echo $bg; ?>"><a href='report.php?report_id=<?php echo $result['report_id']; ?>'>Here</a></td> </tr> <? $n++; } ?> </tbody> </table> Which works great. Now the only problem I have is with this line: <td bgcolor="<?php echo $bg; ?>"><a href='report.php?report_id=<?php echo $result['report_id']; ?>'>Here</a></td> As there may not be a report_id available. So how can I change it to say if there is a report_id then output that line, but if not output the words no report Thanks Chris Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 11, 2007 Share Posted July 11, 2007 Please edit your post and surround the code with [code] and [/code] tags! Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 <td bgcolor="<?php echo $bg; ?>"><a href='report.php?report_id=<?php echo $result['report_id']; ?>'>Here</a></td> Try this, <?php if(!empty($result['report_id'])) { ?> <td bgcolor="<?php echo $bg; ?>"><a href='report.php?report_id=<?php echo $result['report_id']; ?>'>Here</a></td> <?php } else { echo "no eeport"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.