PHP - 没有找到记录

时间:2011-02-08 06:16:16

标签: php mysql record

我是非常非常新的PHP,我正在尝试修复别人写的代码。我设法做了几个修复,现在搜索工作正常,但我无法获得“找不到记录”的消息。

我是一个尝试自学的新手,所以任何反馈都会受到赞赏。提前谢谢。

这是我的代码:

  

块引用

<?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 $data_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> 
  

块引用

2 个答案:

答案 0 :(得分:5)

您只想显示该消息?把它放在while循环之前或之后:

<?php 
if (mysql_num_rows($rs_main) == 0) {
    echo "No records found.";
}
?>

答案 1 :(得分:2)

查询后,计算结果:

if(mysql_num_rows($rs_main)>0)
{
 //put your code above here 
}
else
{
 echo 'No records found!';
}