![]() |
How can I make my select variable match exact - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How can I make my select variable match exact (/showthread.php?tid=52606) |
How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]msank[/eluser] Hey there, I need some help with getting my select statement to return EXACTLY what I asked it to look for, not 'search variable' + anything else that has that in it's value; eg Magnetics is from the row 'name'. I am searching for ALL products from "Magnetics" and ONLY them. Currently I am getting all companies with "Magnetics" in their name... I have tried the following in my model: Code: function searchInventory($search) { but it returns no results. This is my form: Code: <?php This is my controller for the page the form is on: Code: function search() { Any ideas? Thanks! How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]Matalina[/eluser] don't add the % to the like statement. How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]msank[/eluser] I added that to try to see if it would work, after I was having issues with getting more than I was wanting (Other companies aside from Magnetics) and it would return nothing. Before I added that, it was returning more than I needed, and wanted. How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]Matalina[/eluser] Code: function searchInventory($search) { did you try that? How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]msank[/eluser] Yep... That's what I had originally and is returning more than I want. How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]Matalina[/eluser] 1. Why are you using a like statement if you want ONLY Magnetics? Why not a straight Where = clause? Code: $this->db->or_where('name', $search); 2. Use the third parameter (http://ellislab.com/codeigniter/user-guide/database/active_record.html) Needed quote: Quote:If you do not want to use the wildcard (%) you can pass to the optional third argument the option 'none'. Code: $this->db->or_like('name', $search,'none'); How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]msank[/eluser] Quote: This fixed my issue! Thanks so much for the stellar help! I really appreciate it! How can I make my select variable match exact - El Forum - 06-18-2012 [eluser]Matalina[/eluser] no problem. |