我刚学PHP  想做一个很简单站内搜索。 页面是这样的:--------------------------------------------------------------
Pestcide_trade_name: (一个下来菜单)
Company name: (一个下拉菜单)
Active ingredient:(一个下拉菜单)Application:(一个textarea)
Enviroment:(一个textarea)
-------------------------------------(上面的在数据库的一个表里insecticide, 下面的在表crop里)
Crops: (一个下拉菜单)
REI:(一个下拉菜单)
Note: (一个textarea)Search button------------------------------------------------------------------Pestcide_trade_name和ID 是主键。数据库一共两张表, 上面5个在表insecticide里,下面三个在crop里。
我想做到的就是  Pestcide_trade_name和crop是必须选的,没选择要给提示要求选择。 其他的条件可选可不选,然后结果就是把所有符合选中条件的结果显示出来放在一个表格里打出来。我写的search.php:----------------------------------------------------------------------------------------------------------
 if (isset($_POST['TN'])&&!empty($_POST['TN'])&&isset($_POST['Crops'])&&!empty($_POST['Crops'])){
     $searchp = "select ID, Pestcide_trade_name, Crops from insecticide, crop where insecticide.Pestcide_trade_name='".$_POST['TN']."' and crop.Crops='".$_POST['Crops']."'and insecticide.ID =crop.ID ";

if(isset($_POST['CN'])&&!empty($_POST['CN'])) 
$searchp.="and insecticide.Company_name='".$_POST['CN']."'";
         if(isset($_POST['AI'])&&!empty($_POST['AI'])) 
$searchp.="and insecticide.Active_ingredient='".$_POST['AI']."'";
if(isset($_POST['PPE'])&&!empty($_POST['PPE'])) 
$searchp.="and insecticide.PPE='".$_POST['PPE']."'";


if(isset($_POST['REI'])&&!empty($_POST['REI'])) 
$searchp.="and crop.REI='".$_POST['REI']."'";//and crop.Pestcide_trade_name='".$_POST['TN']."' and crop. ID = insecticide.ID";
           
$resultp=mysql_query($searchp);
                
echo"<table class='table1' style= 'table-layout:fixed; width:900px; '><tr><td style= 'width:50px;'>ID</td><td style= 'width:80px;'>Company Name</td><td style= 'width:80px;'>Trade name</td><td style= 'width:80px;'>Active Ingredient</td><td style= 'width:50px;'>PPE</td><td>Applicators Must Wear</td><td>Mixers/loaders Must Wear</td><td>Environmental Hazards</td><td>CROPS</td><td>REI</td></tr>"; ($rs=mysql_fetch_object($resultp)){
   
echo '<tr><td >'.$rs->ID.'</td><td>'.$rs->Company_name.'</td><td>'.$rs->Pestcide_trade_name.'</td><td>'.$rs->Active_ingredient.'</td><td width:50px>'.$rs->PPE.'</td>';
echo '<td style="word-break: keep-all;"><div style="word-break:break-all;word-wrap:break-word;"> <pre>'.$rs->AMW.'</pre></div></td><td style="word-break: keep-all;width:300px"><div style="word-break:break-all;word-wrap:break-word"> <pre>'.$rs->MMW.'</pre></div></td><td style="word-break: keep-all;"><div style="word-break:break-all;word-wrap:break-word"> <pre>'.$rs->EH.'</pre></div></td><td style="word-break: keep-all;"><div style="word-break:break-all;word-wrap:break-word;"> <pre>'.$rs->Crops.'</pre></div></td><td style="word-break: keep-all;"><div style="word-break:break-all;word-wrap:break-word;"> <pre>'.$rs->REI.'</pre></div></td></tr>';   
   
 }
  echo'</table>';
--------------------------------------------------------------------------------------------------------------代码总报错Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in d:\apm_setup\htdocs\search.php on line 67哪位能帮我看看我写要怎么改。 万分感谢啊!!!!!!!!!!!!

解决方案 »

  1.   

    $resultp=mysql_query($searchp) or die(mysql_error());  //报什么错
      

  2.   

    Į��: 'ID' in 'field list' �� ��ȣ�
    这是什么意思??
      

  3.   

    现在是UTF-8  要改成什么编码呢?
      

  4.   

    我觉得是我search.php的整体code有问题。哪位能帮我看看code呢 虽然代码很长,唉拜托啦~  新手自学php, 自己琢磨不出来了~  如果你能帮我search成功, 我加分也是可以的。谢谢。
      

  5.   

    改成gbk看看。贴出没有乱码的错误信息。
      

  6.   

     
    我没有gbk 只有GB2312  出来的错误信息还是乱码 : 
    漠烦: 'ID' in 'field list' 捞 葛龋窃能不能多占用下你的时间 帮我看看我的代码呢。 先谢谢下!
      

  7.   


    程序是charset=utf-8 浏览器也是utf-8  可报错的信息就是乱码 唉
      

  8.   

    输出你的SQL语句到mysql里执行看看结果就知道了.SQL语句有问题
      

  9.   

    $searchp = "select ID, Pestcide_trade_name, Crops from insecticide, crop where insecticide.Pestcide_trade_name='".$_POST['TN']."' and crop.Crops='".$_POST['Crops']."'and insecticide.ID =crop.ID ";
    这里有问题吧  是哪里有什么语法错误吗?  
    我的想法是  从insecticide和crop 两个表中 选出ID相同,并且insecticide.Pestcide_trade_name为$_POST['TN']的, crop.Crops为$_POST['Crops']的。
      

  10.   

    新鸟过来给你支支招吧。
    1.$_post[]不要直接引用。
    $a=$_post['tn'];    $b=$_post['crops'];
    2,sql语句不能这么写。
    select *(我简写为*,你自己加) from (select * from table where crops=$b) where trade_name =$a;
    或者用union来写sql
      

  11.   

    Į��: 'ID' in 'field list' �� ��ȣ�
    类似xx  in 'field list'
    大部分出这错  是sql语句的问题
    应该是不知道你的ID 字段、
      

  12.   

    最后看了看你的sql
    可能出在这里的问题
    select insecticide.ID,  省略中间  and insecticide.ID =crop.ID 新手不懂php噢、
      

  13.   

    亲, sql语句这里insecticide.ID =crop.ID 有问题把? 如果你的insecticide的ID要跟crop的ID匹配, 这条语句应该要使用表连接吧? 具体请查看left join等表连接语句的用法, 估计你的问题就是出现在这里
      

  14.   

    $resultp=mysql_query($searchp) or die(mysql_error()); //报什么错 
    恩恩,应该是这样