我从外面传入$ids,$ids是如 '2676','2675','2674','2683','2682'此类id号,但每次都显示error,但我用输出来的sql语句在SQLyog里查却可以查出来,纠结啊!!!请各位帮我看看,小弟实在无力啦!!!
页面上输出:
select `p_name`, `p_53kf_price` from `cs_product` where `id` in ('2676','2675','2674','2683','2682')error 
功能代码如下:function get_product($ids)
{
  $sql="select `p_name`, `p_53kf_price` from `cs_product` where `id` in (".$ids.")";
  echo $sql;
  $re1=db_query($sql);
  //echo "<br/>".count($re1)."<br>".$re1."<br/>";
  if($re1!==false && count($re1)>0)
  {
foreach($re1 as $v)
{
   
        }
  }else{
    echo "error";
  }
  return $list;}数据库代码如下/*返回多条记录 2维数组*/
function db_query($sql)
{
  global $dblink;  $rs = mysqli_query($dblink,$sql);
  if (!$rs)
  {
    error_log("SQL ERROR: $sql",0);
    return false;
  }  if ($rs===true)
  {
    //可能执行insert update delete
    $rows = true;
  }
  else
  {
    $rows = array();
    while ($row=mysqli_fetch_assoc($rs)) $rows[] = $row;
    mysqli_free_result($rs);
  }
  return $rows;
}

解决方案 »

  1.   

    用这句试试
    select p_name, p_53kf_price from cs_product where id in (".$ids.")
      

  2.   

    $re1=db_query($sql);
    print_r($rel);
      

  3.   

     if ($rs===true)
      {
        //可能执行insert update delete
        $rows = true;
      }
      else
      {
        $rows = array();
        while ($row=mysqli_fetch_assoc($rs)) $rows[] = $row;
        mysqli_free_result($rs);
      }
      return $rows;
    这里有问题 ,你的变量$rows作用域有问题 ,if 和else结束后$rows就没了所以没有结果
    解决办法是在if之前加上$rows = array()
      

  4.   

    $rs = mysqli_query($dblink,$sql);
    改成 $rs = mysql_query($dblink,$sql);楼主试试!
      

  5.   

    rs = mysql_query($sql,$dblink);
      

  6.   

    加一句
    $ids=str_replace("&#039;","'",$ids);
    先替换掉‘,谁能解释下?
      

  7.   

    这种问题你打印一下sql就看出来了,然后看源码$ids=str_replace("&#039;","'",$ids);实体替换为'号,没有转义,sql语句出错
      

  8.   

    (".$ids.")";
    这里是不是应该这样(’".$ids."‘)";
    另外,你传进来的$ids到底是几个id呢,是不是需要循环一下读出每一个id啊
      

  9.   

    $ids = array(1,2,3,4,5);
    $sql="select `p_name`, `p_53kf_price` from `cs_product` where `id` in ("'".implode("','", $ids)."')";
    $query = mysql_query($sql);
    while($value = mysql_fetch_array($query)) {
         $list[] = $value;
    }
      

  10.   

    $ids在传值的时候单引号有没有被转义,或被替换成其他的了。
      

  11.   

    例如,你传过去的参数为 querydb('1,2,3,4'),而不是('1','2')
      

  12.   

    select `p_name`, `p_53kf_price` from `cs_product` where `id` in ('2676,2675,2674,2683,2682')
    你的ID是数值