我需要一些使用LIKE和NOT LIKE的帮助...我有一个查询,我通过WHERE子句通过基于我的请求变量来自另一个服务器。其中一个查询如下所示:MySQL和PHP - 使用'LIKE'和'NOT LIKE'
'CONNECT' =>
"(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%'
)",
您可以看到我使用了LIKE而不是LIKE。不幸的是,这种方式并不按照我希望的方式工作。我猜这是因为我要求PORT,但不是REPORT,所以无论如何它都给了我LIKE。
我想知道在这种情况下我应该做些什么。我正在考虑将另一个查询或数组作为“排除列表”使用。如果查询是LIKE语句,我可以在我的WHERE子句中使用'table_uid NOT IN(COMMA SEPARATED UID列表)'。
我有我的LIKE语句,我想排除:
$exclude_where_clauses = array(
'CC' => "(detail_head.comment LIKE '%ccb%') ",
'CONNECT' => "(detail_head.comment LIKE '%report%' OR detail_head.comment LIKE '%portal%') ",
'EO' => "(detail_head.comment LIKE '%OCU%' AND detail_head.comment LIKE '%KS%' AND detail_head.comment LIKE '%screen%' AND detail_head.comment LIKE '%term%') ",
'INVENTORY' => "(detail_head.comment LIKE '%discount%') ",
'KS' => "(detail_head.comment LIKE '%panel%' or detail_head.comment LIKE '%PMIX%' or detail_head.comment LIKE '%pmix%') ",
'OCUS' => "(detail_head.comment LIKE '%document%') ",
'SALES' => "(detail_head.comment LIKE '%point%') ",
'SECURITY' => "(detail_head.comment LIKE '%km%') ",
'TERMS' => "(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%') ",
);
所以,到最后,我想转产我目前的查询阵列说"(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) "
请张贴一个例子评论,也一样,所以我们可以看到在上下文中的“报告”和“端口”。 – 2013-05-13 13:35:43
另外请注意,我认为我最想做的事情是编码出来......我只是不确定它会如何工作: – brandoncluff 2013-05-13 13:36:30
$ exclude_where_clause = $ exclude_where_clauses [$ _ REQUEST ['count_request']]; $ not_like_qry =“SELECT detail_head.scr FROM detail_head WHERE detail_head.call_status!='c'AND call_origins_uid!= 5 AND $ exclude_where_clause”; $ qry。=“AND call_origins_uid!= 5 GROUP BY detail_head.scr”; $ dob-> setQuery($ not_like_qry); ($ dob-> fetch(MYSQL_ASSOC)){ $ rows [] = $ dob-> getRowAsArray(); } foreach($ rows as $ row){ fputcsv($ tmpdata,$ row,'|'); } – brandoncluff 2013-05-13 13:37:51