Show message if mysql_query returns no results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeffyyy
Forum Newbie
Posts: 17
Joined: Sat Apr 24, 2010 9:06 pm

Show message if mysql_query returns no results

Post by jeffyyy »

Here is what I have, I need it to display a message if the query returns no results. Thanks!

Code: Select all

<?php
$term = $_POST['term'];

$sql = mysql_query("select * from messages where tag like '$term'");

while ($row = mysql_fetch_array($sql)){
?><table width="75%" padding="0" border="1">
  <tr>
    <td width="65%">
    <a id="inline" href="#<?php echo ''.$row['message_id'];?>">
	<?php echo 'Message From: '.$row['name'];?></a>
    </td>
    <td><br /> <?php echo ' '.$row['date'];?></td>
<div style="display:none">
<div id="<?php echo ''.$row['message_id'];?>">
<?php echo 'Message:<br /> '.$row['message'];?>
</div>
</div>
</td>
  </tr>
</table>
<?php
	}
?>
phu
Forum Commoner
Posts: 61
Joined: Tue Mar 30, 2010 6:18 pm

Re: Show message if mysql_query returns no results

Post by phu »

Post Reply