各位好,问题是这样的:
前面一个页面main.php的url传值是pro.php?subName=x
在pro.php页面要如何写这个select语句呢?(这个subName字段是set类型的[复选框],值可能是x,y,z)
比如有纪录:
id    Name   subName
1      a        x
2      b       x,y
3      c       y,z
pro.php页面的这个sql要怎么写呢,我要显示出第一和第二条纪录.如何把subName字段中的x剥离出来?
$sql="select * from product where ?";一直先线,谢谢各位了

解决方案 »

  1.   

    $sql="select * from product where subName='x'"; 这样不行?
      

  2.   

    $str = 'x,y,z';
    $subs = explode(',',$str);
    $con = count($subs) >= 2 ? implode(',',array_slice($subs,0,2)) : $subs[0];
    $sql = "select * from product where subName IN ($con)";
    echo '<br>' , $sql , '<br>';  
      

  3.   

    $sql="select * from product where subName like %x%?";
      

  4.   

    $sql="select * from product where subName like %x%?";
    $sql="select * from product where subName='x'"; 
    这都不行哦 
    thinkinginAOCP 这个貌似也不行
      

  5.   

    我硬是没了解楼主的需求 什么叫把subName字段中的x剥离出来?
      

  6.   

    $sql="select * from product where find_in_set('x',subName)";  
      

  7.   

    其实就是地址栏的链接.
    有一个链接:<a href="pro.php?subName=DVB-T">DVB-T</a>
    数据表product中的纪录:
    id      Name             subName
    1        a               DVB-T,rf cable,pc cam,fiber
    2        b               DVB-T
    3        c               Driver,led
    现在我想读出数据表product中的第一条和第二条纪录(字段subName中包含有DVB-T),我不知道在pro.php页面如何写sql语句?我意思就是只要字段subName中包含有DVB-T就显示出这条纪录。
    --可能是我表达不清楚吧,真是抱歉..
      

  8.   

    SELECT * FROM product WHERE FIND_IN_SET('x',subName)>0; 
    或者
    SELECT * FROM product WHERE subName LIKE '%x%';