Welcome Guest, Not a member yet? Register   Sign In
i want to convert this sql query to codeigniter query
#1

[eluser]minhbu[/eluser]
select * from class where id=3 and (name like "%a" or name like "a%" or name like "%a%" )
help me !
#2

[eluser]umefarooq[/eluser]
try this

Code:
$this->db->get('class')
$this->db->where(array('id'=>3))
$this->db->like(name,'a','before')
$this->db->or_like(name,'a','after')
$this->db->or_like(name,'a')

before will put % before a, after will put % after a , default is on both side.

check the link will help you more http://ellislab.com/codeigniter/user-gui...ecord.html
#3

[eluser]Milos Dakic[/eluser]
@umefarooq; I think you forgot quotes around the name field Wink

Code:
$this->db->get('class')
$this->db->where(array('id'=>3))
$this->db->like('name','a','before')
$this->db->or_like('name','a','after')
$this->db->or_like('name','a')
#4

[eluser]umefarooq[/eluser]
yes thanks @Milos Dakic for correction
#5

[eluser]minhbu[/eluser]
[quote author="Milos Dakic" date="1235738733"]@umefarooq; I think you forgot quotes around the name field Wink

Code:
$this->db->get('class')
$this->db->where(array('id'=>3))
$this->db->like('name','a','before')
$this->db->or_like('name','a','after')
$this->db->or_like('name','a')
[/quote]
but when i query this code is
select * from class where id=3 and name like "%a" or name like "%a%" or name like "a%"
i want
select * from class where id=3 and (name like "%a" or name like "%a%" or name like "a%")
#6

[eluser]pehaw[/eluser]
I would have said that

“%a” and “a%”

are subsets of “%a%” , so you don't need all of those ORs anyway.




Theme © iAndrew 2016 - Forum software by © MyBB