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 Link to comment https://forums.phpfreaks.com/topic/59414-help-with-a-while-loop/ 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! Link to comment https://forums.phpfreaks.com/topic/59414-help-with-a-while-loop/#findComment-295206 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/59414-help-with-a-while-loop/#findComment-295216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.