• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[ SOLVED ] SQL Like Handling (Active Record class)

#11
[eluser]tkaw220[/eluser]
Thanks ci user. Guest I wish to learn more about CI. Thanks.

#12
[eluser]tkaw220[/eluser]
[quote author="ci user" date="1307379921"]I guess i could not work it by active record method.


Please try this..

$query = $this->db->where('(publish !=\'no\')')->or_like($data)->order_by('brand, format, title', 'asc')->get('products');

Thanks,
ci user.[/quote]

This code is same as mine in the first post.

#13
[eluser]theprodigy[/eluser]
Quote:This code is same as mine in the first post.
Code:
$query = $this->db->where(’(publish !=\‘no\’)’)->or_like($data)->order_by(‘brand, format, title’, ‘asc’)->get(‘products’);
Not exactly. ci user specifically added the parenthesis into the where clause for the 'publish != 'no' part.
Yours did not have these parenthesis hard coded.

#14
[eluser]tkaw220[/eluser]
[quote author="theprodigy" date="1307431764"]
Quote:This code is same as mine in the first post.
Code:
$query = $this->db->where(’(publish !=\‘no\’)’)->or_like($data)->order_by(‘brand, format, title’, ‘asc’)->get(‘products’);
Not exactly. ci user specifically added the parenthesis into the where clause for the 'publish != 'no' part.
Yours did not have these parenthesis hard coded.[/quote]

Hi theprodigy and ci user:

@theprodigy: Thanks for pointing out the difference.

@ci user: I cannot thank you enough for the inspiration from your 'WHERE' clause. I did not notice that I can use it like this. Your code inspired me to come out with below code, which I think it is cleaner, and it works the way I want it:

Code:
$query = $this->db
        ->where('(`publish` !=\'no\')')
        ->where("(`title` LIKE '%$keyword%' OR `brand` LIKE '%$keyword%' OR `property` LIKE '%$keyword%' OR `group` LIKE '%$keyword%' OR `format` LIKE '%$keyword%' OR `isbn` LIKE '%$keyword%')")
        ->order_by('brand, format, title', 'asc')
        ->get('products');

var_dump:

Code:
'SELECT *
FROM (`products`)
WHERE (`publish` !='no')
AND (`title` LIKE '%transformers 3%' OR `brand` LIKE '%transformers 3%' OR `property` LIKE '%transformers 3%' OR `group` LIKE '%transformers 3%' OR `format` LIKE '%transformers 3%' OR `isbn` LIKE '%transformers 3%')
ORDER BY `brand`, `format`, `title` asc'

I hope the above finding may benefit other CI users. Please update me if there is other better and cleaner way to to this.

Thanks and have a nice day.

Regards,
Edwin

#15
[eluser]plain jane[/eluser]
tkaw220,

Thanks for your solution it helped me.

Have a nice day.

Thanks,
ci user

#16
[eluser]tkaw220[/eluser]
Hi ci user,

Not at all. The code is not possible without your help.

I have another issue with URL, would appreciate if you could help me. Let said I have a controller named new_product, and my subsequence URL might look like this:

Code:
http://www.domain.com/index.php/new_product/disney_book OR

http://www.domain.com/index.php/new_product/get_product/12

I would like to make the URL search engine friendly where underscore replaced with dash like this:

Code:
http://www.domain.com/index.php/new-product/disney-book OR

http://www.domain.com/index.php/new-product/get-product/12

I aware of CI url_title() function but do not know how and where to implement it to turn my URL human friendly.

Huge thanks to you in advanced.

#17
[eluser]plain jane[/eluser]
Thank you for appreciation.

I have not worked in url rewriting and sorry for that. But here is an article you may find helpful.

Quote:http://stackoverflow.com/questions/21050...ith-hyphen

Thanks,
ci user

#18
[eluser]tkaw220[/eluser]
[quote author="ci user" date="1307448844"]Thank you for appreciation.

I have not worked in url rewriting and sorry for that. But here is an article you may find helpful.

Quote:http://stackoverflow.com/questions/21050...ith-hyphen

Thanks,
ci user[/quote]

It is OK. Thanks for the finding.

Have a nice day.

#19
[eluser]plain jane[/eluser]
Remove the index.php from your URLs to make them SEO friendly.

Thanks, ci user

#20
[eluser]tkaw220[/eluser]
[quote author="ci user" date="1307449511"]Remove the index.php from your URLs to make them SEO friendly.

Thanks, ci user[/quote]

Will do that, thanks for the mentioned.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.