代码如下:<?php
    // $str1=$_POST["u_field"];
     //$str2=$_POST["u_key"];
     $sql=mysql_query("select count(*) as total from ruku where ".$_POST[u_field]." like '%".$_POST[u_key]."%'",$conn) ;
     $info=mysql_fetch_array($sql) or die(mysql_error()) ;
     $total=$info[total];
     if($total==0)
    {
    echo "<tr align='center'><td  > >没有找到相关记录</td></tr>";
    } 
    else
    {
       $pagesize=2;
       if ($total<=$pagesize){
          $pagecount=1;
       } 
       if(($total%$pagesize)!=0){
  $pagecount=intval($total/$pagesize)+1;
       }else{
    $pagecount=$total/$pagesize;
            }
        if(($_GET[page])==""){
          $page=1;
        }else{
             $page=intval($_GET[page]);
}
    }
  $sql1=mysql_query( "select id,name,lot_number,r_data,supplier,custos,deal_name,comment from ruku where ".$_POST[u_field]." like '%".$_POST[u_key]."%' limit " .($page-1)*$pagesize.",$pagesize ",$conn) or die(mysql_error());
     while($rows = mysql_fetch_row($sql1)) {
echo "<tr>";
for($i = 0; $i < count($rows); $i++){ 
if ($rows[$i] == "")
echo "<td height='30'>&nbsp;</td>";
     else
echo "<td height='30' align='center' valign='middle'>&nbsp;".$rows[$i]."&nbsp;</td>";
}
echo "<td><a href='modify_staf.php?id=".$rows[0]."'>修改</a>/<a href='del_staf_chk.php?id=".$rows[0]."'onclick='return del_chk();'>删除</a></td>";
echo "</tr>";
   }
?>
代码执行后,能够查找,也能够实现分页,但是当点击页码的时候会报错。
错误提示如下:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\dihoclient\storeroom\ruku\found_staf_chk.php on line 46
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%'' at line 1 。
可看了半天也不知道那个“like”那出了什么问题!

解决方案 »

  1.   

    调试中检查一下当时的SQL语句是什么?
      

  2.   

    可能吗?楼主是怎么检查的?     $sql=mysql_query("select count(*) as total from ruku where ".$_POST[u_field]." like '%".$_POST[u_key]."%'",$conn) ;
         echo "select count(*) as total from ruku where ".$_POST[u_field]." like '%".$_POST[u_key]."%'"
         $info=mysql_fetch_array($sql) or die(mysql_error()) ;
         $total=$info[total];
      

  3.   

    显示:
    select count(*) as total from ruku where name like '%11%'
      

  4.   

    select count(*) as total from ruku where name like '%11%'直接到MYSQL中去运行一下试试
      

  5.   

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,2' at line 1 
      

  6.   

    能直接贴你的MYSQL中执行的错误界面吗?
    你好像没有正确测试。 你的语句select count(*) as total from ruku where name like '%11%'中哪儿来的 '0,2'
      

  7.   

    查询时sql语句输出的是:select count(*) as total from ruku where name like '%11%'
    但点击页码后sql语句输出就变成:select count(*) as total from ruku where like '%%'
    发现u_field和u_key的值都没了,我想这是导致出错的原因,但我不知道为什么会没,该怎样能保存住这两个值呢!