我的SQL语句是这样写的:Select ID,ParentsID,ProName,ProSImg,SImgAlt,HtmlUrl From ProductsInfo where IsShow=True and instr(','ParentsID_r',',',".$_REQUEST["list"].",')>0 Order By ToSort desc
整个代码是这样的<?php 
 $str="Select ID,ParentsID,ProName,ProSImg,SImgAlt,HtmlUrl From ProductsInfo where IsShow=True and instr(','ParentsID_r',',',".$_REQUEST["list"].",')>0 Order By ToSort desc";
 $result=mysql_query($str,$link);
 $num=mysql_num_rows($result);
 for($i=0;$i<$num;$i++)
 {
 $row=msql_fetch_array($result);
 echo $row["ProName"];
 }
 ?>
可是为什么上面传过来的sql语句却查不到值呢,页面上什么也不显示为空白,调试也不报错。请大家帮我看看是哪里出错了。

解决方案 »

  1.   

    IsShow的类型如果是字符串要加引号
      

  2.   

    IsShow的类型不是字符型的,我现在知道是instr(','ParentsID_r',',',".$_REQUEST["list"].",')>0这里错了,但不知道怎么改。
      

  3.   

    $s = "Select ID,ParentsID,ProName,ProSImg,SImgAlt,HtmlUrl From ProductsInfo where IsShow='True' and instr(',ParentsID_r,',',".$_REQUEST["list"].",')>0 Order By ToSort desc";
      

  4.   

    instr(','ParentsID_r',',',".$_REQUEST["list"].",') ???
    你这样写对吗?instr 只有两个参数,返回第一个参数在第二个中第一次出现的位置
      

  5.   

    用你我也试过了,我把条件都满足了在mysql数据库里动行时显示都为空
      

  6.   

    我的ParentsID_r字段里的值为[2,21],$REQUEST["list"]的值为21,可是为什么查询出来的值为空呢?
      

  7.   

    ParentsID_r字段里的值是2,21。我用个[]括起来是为方便大家看。并没有中括号。
      

  8.   

    $s = "Select ID,ParentsID,ProName,ProSImg,SImgAlt,HtmlUrl From ProductsInfo where IsShow='True' and instr('ParentsID_r','" . $_REQUEST["list"] . "')>0 Order By ToSort desc";你这样试试,我没看懂为什么你有那么多逗号和单引
      

  9.   

    本帖最后由 xuzuning 于 2010-09-21 10:34:32 编辑
      

  10.   

    $s = "Select ID,ParentsID,ProName,ProSImg,SImgAlt,HtmlUrl From ProductsInfo where IsShow='True' and instr(',ParentsID_r,',',".$_REQUEST["list"].",')>0 Order By ToSort desc";
    你的意思是不是后面一个参数是  ,"21",如果是这样的话  是你拼接字符串的问题吧
    应该是instr(',ParentsID_r,',',\"'.$_REQUEST["list"].'\",') 而且mysql中的双引号貌似也要转义
    你这个东西太麻烦了   我没测试  你多测试测试就好了  关键你这里的符号太多了
      

  11.   

    instr(concat(',',ParentsID_r,','), ',{$_REQUEST[list]},')>0
      

  12.   

    echo $str ;
    看看输出啥
      

  13.   

    php没有instr()这个函数吧?是自定义的吗?
    SQL语句中应该这样写才对吧?
    instr(','+ParentsID_r+',',',".$_REQUEST["list"].",')>0