Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL and PHP - using 'LIKE' AND 'NOT LIKE'
    primarykey
    data
    text
    <p>I need some help with using LIKE and NOT LIKE together... I have a query that I pass WHERE clauses through based on what my request variable is from another server. One of the queries is like the following: </p> <pre><code> 'CONNECT' =&gt; "( detail_head.comment LIKE '%port%' or detail_head.comment LIKE '%forward%' or detail_head.comment LIKE '%connect%' or detail_head.comment LIKE '%router%' or detail_head.comment LIKE '%fire%wall%' or detail_head.comment LIKE '%sonic%' ) AND ( detail_head.comment NOT LIKE '%report%' OR detail_head.comment NOT LIKE '%portal%' )", </code></pre> <p>You can see that I am using LIKE and NOT LIKE. This unfortunately does not work the way I hoped it would. I am guessing it's because I am asking for PORT, but not REPORT, so it gives me the LIKE regardless. </p> <p>I was wondering what I should do in a case like this. I was thinking about making another query or array that I would use as an 'exclude list'. Where the queries would be LIKE statements, that I could use in my WHERE clause to say 'table_uid NOT IN(LIST OF COMMA SEPARATED UIDs)'.</p> <p>I have my LIKE statements that I'd like to exclude: </p> <pre><code>$exclude_where_clauses = array( 'CC' =&gt; "(detail_head.comment LIKE '%ccb%') ", 'CONNECT' =&gt; "(detail_head.comment LIKE '%report%' OR detail_head.comment LIKE '%portal%') ", 'EO' =&gt; "(detail_head.comment LIKE '%OCU%' AND detail_head.comment LIKE '%KS%' AND detail_head.comment LIKE '%screen%' AND detail_head.comment LIKE '%term%') ", 'INVENTORY' =&gt; "(detail_head.comment LIKE '%discount%') ", 'KS' =&gt; "(detail_head.comment LIKE '%panel%' or detail_head.comment LIKE '%PMIX%' or detail_head.comment LIKE '%pmix%') ", 'OCUS' =&gt; "(detail_head.comment LIKE '%document%') ", 'SALES' =&gt; "(detail_head.comment LIKE '%point%') ", 'SECURITY' =&gt; "(detail_head.comment LIKE '%km%') ", 'TERMS' =&gt; "(detail_head.comment LIKE '%forward%' or detail_head.comment LIKE '%sales%' or detail_head.comment LIKE '%intermittent%' or detail_head.comment LIKE '%print%' or detail_head.comment LIKE '%de%min%' or detail_head.comment LIKE '%reciept%' or detail_head.comment LIKE '%time%') ", ); </code></pre> <p>So, in the end, I'd like to be converting my current array of queries to say <code>"(detail_head.comment LIKE '%port%' or detail_head.comment LIKE '%forward%' or detail_head.comment LIKE '%connect%' or detail_head.comment LIKE '%router%' or detail_head.comment LIKE '%fire%wall%' or detail_head.comment LIKE '%sonic%') AND table_uid NOT IN(LIST OF COMMA SEPARATED UIDs) "</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload