Jump to content

Help with a while loop


Mr Chris

Recommended Posts

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

<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";
}
?>

 

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.