Dynamic where problem

From: Date: Wed, 15 Dec 2004 10:08:51 +0000
Subject: Dynamic where problem
Groups: php.db 
Request: Send a blank email to php-db+get-37691@lists.php.net to get a copy of this message
I'm running a dynamic query and noticed I was not getting the results expected. Explanation: Here I make the declaration for the query array: $aWHERE = array(); Then test what variables came back from input: if(!empty($aWHERE)) { $query_rsCS .= ' WHERE '.implode(' AND ',$aWHERE); Here is the problem. I have one field in the form that is set to search 1 table on 1 field and another table on 2 fields: if(!empty($sCanEmail)) $aWHERE[] = "Reg.email LIKE '%$sCanEmail%'"; if(!empty($sCanEmail)) $aWHERE[] = "Profiles_AddContacts.eml2 LIKE '%$sCanEmail%'"; if(!empty($sCanEmail)) $aWHERE[] = "Profiles_AddContacts.eml3 LIKE '%$sCanEmail%'"; So, if an email addy is not found in all 3 fields then nada is returned. Obviously ! (all AND statements) Right now my thinking is I "might" need to break these particular "where" conditions off into a seperate array. Something like: $bWHERE = array(); then - $query_rsCS .= ' WHERE '.implode(' OR ',$bWHERE); Or is it possible there is another work around I'm not seeing yet ? Thanks in advance. Stuart

« previous php.db (#37691) next »