doushan5245 2013-03-20 08:09
浏览 85

在Codeigniter,MySQL中没有用LIKE搜索我想要的东西

I have the followings examples in be_user_profiles.subject. These are subject ids which each teacher teaches.

1// English
1,2 // English and Math etc
1,2,14
2,4,114
12,24,34
15, 23

I want to select where be_user_profiles.subject has 1. When I use the following, it outputs all which has 1 in it. So it will outputs all. I tried HAVING but it picks up only exact matches. So it shows only the first one. How can I pick up data which has the be_user_profiles.subject?

    $this->db->select('*');
    $this->db->from('be_user_profiles');
    $this->db->join('be_users', 'be_users.id = be_user_profiles.user_id');
    $this->db->where('be_users.group', $teachergrp);
    $this->db->like('be_user_profiles.subject', $subjectid);
    //$this->db->having("be_user_profiles.subject = $subjectid");// this picks up only exact match 
    $query = $this->db->get();

Thank you in advance.

  • 写回答

3条回答 默认 最新

  • douxun4173 2013-03-20 08:26
    关注

    be_user_profiles table

    row1: 1,2,14
    
    row2: 2,4,114
    
    row3: 12,24,34
    
    row4: 15, 23
    

    To get data with exact match use this query

    $this->db->query("
          SELECT * FROM `be_user_profiles` 
          WHERE subject LIKE '1'
    
          UNION
    
          SELECT * FROM `be_user_profiles` 
          WHERE subject LIKE '1,%'
    
          UNION
    
          SELECT * FROM `be_user_profiles` 
          WHERE subject LIKE '%,1,%'
    
          UNION
    
          SELECT * FROM `be_user_profiles` 
          WHERE subject LIKE '%,1'
    
       ");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)