Running Where Clause with Like Not Working |
Hi guys please help. I'm trying to run a search on one of the tables where i use multiple likes and a where statement. Code below. Where is ignored in this query and thus returning all the data Like searchText in that table. How do i make sure the where clause is not ignored
PHP Code: //** */
(04-18-2023, 05:29 AM)iRedds Wrote: https://codeigniter.com/user_guide/datab...y-grouping Thanks for the response. I had a look at this. Wont the where clause return the exact match. Because was using like to search even if user inputed something similar. For example if user types 2 letters, all contractors with similar characters inputted would appear on the search box list. It does not have to be an exact match.
Try sth like this:
Code: $builder = $db->table('contractors'); use the "where" option in the end and start with like.
(04-18-2023, 09:59 AM)demyr Wrote: Try sth like this:Thanks Demry. I tried this it still ignores the where clause irrespective of its position. This query returns contractor like it should but from all companies. I want it to search and return contractors associated with that company only.
This is bizarre whenever you are using "OR" in a query, it's the best approach to group your query in a manner to avoid conflict.
PHP Code: $builder = $db->table('contractors'); now your WHERE condition on companyId will be executed properly.
Learning Codeigniter
(04-18-2023, 08:48 PM)SubrataJ Wrote: This is bizarre whenever you are using "OR" in a query, it's the best approach to group your query in a manner to avoid conflict. Thank you so much this works as expected. Appreciated!!!!
@remesses_thegreat No probs ehh, happy to help. I hope you get what you were doing wrong. and kindly mark it solved now
Learning Codeigniter
(04-19-2023, 12:51 AM)SubrataJ Wrote: @remesses_thegreat No probs ehh, happy to help. I hope you get what you were doing wrong. and kindly mark it solved now Yes i now understand. Its a great learning curve. Had never found myself writing queries with grouping. Now i will apply this when necessary. I marked as solved |
Welcome Guest, Not a member yet? Register Sign In |