1
votes

I have some issue when I want to search some data from my database using Codeigniter. I want to select data where the level is 0 and 3 with status 1

    tb_user_data :  
         ----------------------------------
        | username | name | level | status |
         ----------------------------------
        | abb      | ab   | 0     | 1      |
        | abc      | aa   | 1     | 1      |
        | aac      | bb   | 2     | 1      |
        | acc      | cc   | 3     | 1      |
         ----------------------------------

script select data 

$data["adm"] = $this->db->where("level", "0")
                        ->or_where("level", "3")
                        ->where("status", "1")
                        ->get('tb_user_data')->result_array();

when I try to search it by the name, the script doesn't working. Or I got some wrong script or anything else?

thank you

1
doesn't work is the WORST thing a programmer should say to a other programmer.. the code doesn't include the name search .. try adding andWhere("name", [name]) - Raymond Nijland
just write the syntax inline in one function where('(a or b) and c') - Faytraneozter
you can ->where_in clause in codeigniter. see below link it will be helpful for you stackoverflow.com/questions/11023318/… - Gufran Hasan
By the way you can debug your sql before see the result using $this->db->last_query(); - Faytraneozter
thank you guys, problem solved - Imam Nur

1 Answers

1
votes

Try this:

$data["adm"] = $this->db->where_in('level', array('0','3'))
                        ->where("status", "1")
                        ->get('tb_user_data')->result_array();