PHP - No Records Found
I am very, very new at PHP and I am trying to fix a code that someone else wrote. I managed to do a couple of fixes and now the search is working, but I just can't get the "No Records Found" message.
I am a novice trying to teach myself, so any feedback is appreciated. Thank you in advance.
Here is my code:
Blockquote
<?php $counter = 0;
while ($data_main = mysql_fetch_object($rs_main)) { ?>
<div id="thumbnail_div">
<a href="more_info.php?id=<?php echo $data_main->iuniqid; ?>"><*image here*/<?php echo $data_main->prefix; ?>_<?php echo stripslashes($data_main->iname); ?>" border="0" /></a><br />
<?php if ($data_main->itype != '') {
$sql_type = " select itype from type where id = ". $data_main->itype;
$rs_type = mysql_query($sql_type);
$data_type = mysql_fetch_object($rs_type); ?>
<*image here*<?php echo $data_main->itype; ?>.*extension*" width="10" height="10" alt="<?php echo $data_type->itype; ?>" title="<?php echo $data_type->itype; ?>" />
<?php } ?>
<?php if ($data_main->iotype != '' ) {
$sql_otype = " select itype from original_type where id = ". $data_main->itype;
$rs_otype = mysql_query($sql_otype);
$data_otype = mysql_fetch_object($rs_otype); ?>
<*image here*<?php echo $data_main->iotype; ?>.*extension*" width="10" height="10" alt="<?php echo $data_otype->itype; ?>" title="<?php echo $da开发者_如何学编程ta_otype->itype; ?>" /><br />
<?php } ?>
<span class="textBody">Image ID <?php echo $data_main->iuniqid; ?></span>
</div>
<?php $counter++;
if ($counter == 5) {
$counter = 0; ?>
<div id="separatordiv"> </div>
<?php }
} ?>
<div style="clear:both;"></div>
<div align="center"><?php echo $page->get_page_nav(); ?></div>
Blockquote
You just want to show that message? Put this before or after the while loop:
<?php
if (mysql_num_rows($rs_main) == 0) {
echo "No records found.";
}
?>
After your query, count the results:
if(mysql_num_rows($rs_main)>0)
{
//put your code above here
}
else
{
echo 'No records found!';
}
精彩评论