select chr_id,title,author,ctime,htis,type,content from info
    where 
          title like '%$key$%' 
    or    author like '%$key$%'  
    or    ctime like '%$key$%' 
    or    htis like '%$key$%' 
    or    content like '%key%' 
    and  type=#type#
    order by  ctime desc  
    limit #strindex#,#pageNum#;
我做模糊查询 条件是:根据 type和输入的关键字做模糊查询
假如:数据库里面有type 1,和2,
1,2中都有关键字“x”
用户输入的关键字 为 "x" 用户想要的只是所有type=1中的“x”
2中"x"不要查询出来
请问我上面的语句有问题吗

解决方案 »

  1.   

    请问你的sql语句报什么问题呢?
      

  2.   

    你的sql语句都是or,type对以上的模糊查询没有作用,只对最后一个起了作用,你试下select chr_id,title,author,ctime,htis,type,content from info
    where  
    (title like '%$key$%'  
    or author like '%$key$%'   
    or ctime like '%$key$%'  
    or htis like '%$key$%'  
    or content like '%key%')  
    and type=#type#
    order by ctime desc   
    limit #strindex#,#pageNum#;