codeigniter中的SQL LIKE运算符

时间:2016-12-01 00:53:56

标签: php mysql codeigniter

如果有这个表

COLUMN MODE

我想根据学校中的数据返回查询,例如,如果USER TABLE中的private数据为PRIVATE TABLE,我希望它仅在public中搜索如果PUBLIC TABLE只返回if($search){ $search_str = '(user.name LIKE '%{$search}%' OR private.private_name LIKE '%{$search}%' OR public.public_name LIKE '%{search}%' )'; $this->db->where($search_str,NULL,FALSE); $this->db->join("private","private.id = user.id","LEFT"); $this->db->join("public","public.id = user.id","LEFT"); }

中的数据

这是我的代码

mode

如果我的关键字在搜索框中为private mode,则会返回public mode和{{1}}

1 个答案:

答案 0 :(得分:0)

import java.util.Scanner;

public class Grade
 {
 public static void main(String[] args)
 {
        int Agrade=0; //different variables used throughout the code
        int Bgrade=0;
        int Cgrade=0;
        int Dgrade=0;
        int Fgrade=0;
        int count=0;




    Scanner in = new Scanner(System.in);   //name of Scanner 

    System.out.println("Please enter the exam grades one after the other ");
    System.out.println("Please enter a negative number at the end of the grade list to control the flow and then press enter :");
    int score = in.nextInt(); //stores numbers inputted

    System.out.println("Please enter the grades again for the largest number: ");
    double largest = in.nextDouble();


    while (in.hasNextDouble()){
       double input = in.nextDouble();
       if (input > largest) {
          largest = input;
       }
    }



 while(score>0)   //start while loop
     {
       count++;
 if(score>=70 && score<=100)
        Agrade++;
    else if(score>=60 && score<=69)
        Bgrade++;
    else if(score>=50 && score<=59)
        Cgrade++;
    else if(score>=40 && score<=49)
        Dgrade++;
    else if(score>=0 && score<=39)
        Fgrade++;
    score = in.nextInt();
 } //end while



 System.out.println("Total number of grades :"+ count);
 System.out.println("The largest number :"+ largest);
 System.out.println("The number of As :"+ Agrade);
 System.out.println("The number of Bs :"+ Bgrade);
 System.out.println("The number of Cs :"+ Cgrade);
 System.out.println("The number of Ds :"+ Dgrade);
 System.out.println("The number of Fs :"+ Fgrade);

 } // end main
} // end class

在此行$search_str = '(user.name LIKE '%{$search}%' OR (private.private_name LIKE '%{$search}%' AND user.mode = 'private') OR (public.public_name LIKE '%{search}%' AND user.mode = 'public') )'; 中,如果OR (private.private_name LIKE '%{$search}%' AND user.mode = 'private')中的数据等于MODE COLUMN,它会检查USER TABLE中的数据,然后继续private查找指定的数据PRIVATE TABLEkeyword的模式。

在此行PRIVATE NAME COLUMN中,如果OR (public.public_name LIKE '%{$search}%' AND user.mode = 'public')中的数据等于MODE COLUMN,它会检查USER TABLE中的数据,然后转到public查找PUBLIC TABLEkeyword的指定模式。