改成这样看看:echo "<html><head><title>搜索结果</title><meta http-equiv=Content-Type content=text/html; charset=gb2312><link rel=stylesheet href=data/pcpi.css></head>";
 echo "<body bgcolor=#FFFFFF text=#000000 leftmargin=1 topmargin=1 marginwidth=1 marginheight=1>";
 require('data/masthead.inc');
 echo "<table width=760 height=420 border=0 cellspacing=0 cellpadding=0><tr><td width=150 bgcolor=6699CC valign=top>";
 require('data/leftnav.inc');
 echo "</td><td width=10>&nbsp;</td><td valign=top><p><br><b class=maintitle>Product search result</b></p><div align=right><a href=$tb/list.php>返回</a></div><hr size=1>";
 echo "<h4>搜索关键词“<font color=red><b>$pn</b></font>”的结果如下:</h4>";
 mysql_select_db("pcpi",$open);
 $sql="select * from $tb where pn like '%$pn%'";
 $result=mysql_query($sql);if(mysql_fetch_row ( resource result)){    //  此处加什么,才能够使空上if语句能正常工作。echo "<table cellpadding=3 cellspacing=1 border=0 width=450>";while ( $record = mysql_fetch_array($result) ) {
 echo("<tr><td width=40>".$record["id"]."</td><td width=128>".$record["brand"]."</td><td width=109>".$record["pn"]."</td><td width=73><a href=\"$tb/update.php?action=html_update&id=$record[id] \">编辑</a> </td><td width=69> <a href=\"serchreview.php?id=$record[id]&tablename=$tb \">查看</a></td><td>");if(!$record[finalizedate]){
echo "Draft";
}
else echo "Final";
 
echo("</td></tr>");
}echo "</table>";}else {echo "很抱歉,没有找到 <font color=red>".$pn."</font> ,请<a href=".$tb."/index.php?pn=".$pn.">点击添加</a>";
}
echo "<p>&nbsp;</p></td></tr></table>";
require('data/foot.inc');
echo "</body></html>";
?>

解决方案 »

  1.   

    是的,我是想在取值前就进行判断,如果能查到数据就进行读取,并按要求列出来,如果没有查到任何数据就执行else的语句,你给我的例子好象出错了!就是它出错:if(mysql_fetch_row(resource result))
      

  2.   

    出错信息是什么?如果是用POST方法传递变量请使用下面的
    $sql="select * from ".$_POST['tb']." where pn like '%".$_POST['pn']."%'";
    如果是GET方法传递请使用下面的
    $sql="select * from ".$_GET['tb']." where pn like '%".$_GET['pn']."%'";
      

  3.   

    if(mysql_num_rows($result)>0){    //  此处加什么,才能够使空上if语句能正常工作。还有,你确定$tb等值真的传递过来了吗?