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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.