It comes down to detecting if the value you are adding to your list is a continuation of the list or the first item.
You need to set a variable or even a counter at the start of processing then you can use the value of that variable to determine if you are processing the first list item or not. like so... (I am not A PHP programmer so please forgive any syntax erros) $First = TRUE $SQL .= "penpals.agegroup = "; if (isset($HTTP_GET_VARS['check00'])) { // if we are producing the first item in the list // then we do not append the OR if($First) { $First = FALSE; }else{ $SQL .= "OR"; } $SQL .= '00'; } if (isset($HTTP_GET_VARS['check01'])) { if($First) { $First = FALSE; }else{ $SQL .= "OR"; } $SQL .= '01'; } and so on.. the best thing to do is put one block of the above code into a function and pass in the HTTP_GET_VARS string, the SQL string, a ValueSeperator string and First status like so... (again please excuse sytnax, I don't know how to define a function in PHP) FUNCTION (String HttpVarParam, String QueryValueParam, String ValueSeperatorParam, Boolean First){ if (isset($HTTP_GET_VARS['HttpvarParam'])) { // Check if VAR exists in HTTP VARS if($First) { // Is it the first one in our list? $First = FALSE; }else{ $SQL .= ValueSeperatorParam; // if not then we need to append a separator to the list } $SQL .= QueryValueParam; // and don't forget to append the value } } you can then call it like this $First = TRUE $SQL .= "penpals.agegroup = "; CALL FUNCTION ('check00','00','OR', $First) // $SQL will contain "penpals.agegroup = 00" CALL FUNCTION ('check01','01','OR', $First) // $SQL will contain "penpals.agegroup = 00 OR 01" CALL FUNCTION ('check04','04','OR', $First) // $SQL will contain "penpals.agegroup = 00 OR 01 OR 04" The beauty of this is that it is easy to change the sql value that is associated with a n HTTP variable name and you can change the seprator too in case you want your query to be using an IN( , , , ) clause like this... $First = TRUE $SQL .= "penpals.agegroup IN ( "; CALL FUNCTION ('check00','00',',', $First) // $SQL will contain "penpals.agegroup IN ( 00" CALL FUNCTION ('check01','01',',', $First) // $SQL will contain "penpals.agegroup IN ( 00,01" CALL FUNCTION ('check04','04',',', $First) // $SQL will contain "penpals.agegroup IN ( 00,01,04" $SQL .= " )"; // $SQL will contain "penpals.agegroup IN ( 00,01,04 )" That should do the trick... -----Original Message----- From: Don Read [mailto:[EMAIL PROTECTED] Sent: Friday, June 20, 2003 8:32 AM To: vernon Cc: [EMAIL PROTECTED] Subject: RE: Complex SQL involving 10 checkboxes On 19-Jun-2003 vernon wrote: > > OK, I've done this. > > Problem occurs when a user selects 1 and 9. > > The SQL statement I have reads like so: > > if (isset($HTTP_GET_VARS['check00'])) { > $age00 = '00'; > $s_age00 = "penpals.agegroup = $age00 AND"; > } > > Problem is the AND statement. Some times the user will pick checkbox 1 > and 5 > but not 2,3,4,6, 7, 8, and 9. And then again there will be times when a > user > only uses one check box needing the AND statement on the end, but at > other > times the user will select more than one needing an OR statement between > the > two checkboxes. Make sense? > > Use an array. $agesel=implode("', '", $HTTP_GET_VARS['ageselect,]); $qry="SELECT * FROM foo WHERE penpals.agegroup IN ('$agesel')"; Your HTML boxes will look like: <input TYPE=CHECKBOX NAME="ageselect[]" value="00"> <input TYPE=CHECKBOX NAME="ageselect[]" value="10"> <input TYPE=CHECKBOX NAME="ageselect[]" value="15" CHECKED> <input TYPE=CHECKBOX NAME="ageselect[]" value="20" CHECKED> <input TYPE=CHECKBOX NAME="ageselect[]" value="25"> ... Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. (53kr33t w0rdz: sql table query) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]