Well first of all, I am obviously having an off day for using AND at all
in my example.

Why not this?

if (isset($HTTP_GET_VARS['check00'])) {
        $SQL .= "penpals.agegroup = '00' OR";
}

This is probably a question for the PHP general mailing list as it is
more a code question. Essentially you just build the query in chunks. By
the nature of checkboxes you probably just need Ors, not ANDs. You may
need to rip the trailing OR, maybe replacing it with an AND if you need
to add some other condition on the end that needs an AND. Unless of
course someone can belong to more than one agegroup. If so you better
post what the table looks like.

Regards,
Mike Hillyer

> -----Original Message-----
> From: vernon [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 19, 2003 1:25 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Complex SQL involving 10 checkboxes
> 
> 
> 
> 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?
> 
> 
> 
> ---------- Original Message -----------
> From: "Mike Hillyer" <[EMAIL PROTECTED]>
> To: "vernon" <[EMAIL PROTECTED]>, 
> Sent: Thu, 19 Jun 2003 12:57:20 -0600
> Subject: RE: Complex SQL involving 10 checkboxes
> 
> > Well, if one checkbox represents ages 1-5, another represents 6-9, 
> > and another represents 10-15, then you have the checkboxes 
> add where 
> > clauses. Here is a pseudocode/basic example:
> > 
> > *START WITH A SELECT*
> > SQL = "SELECT * FROM TABLE WHERE"
> > 
> > *BUILD THE WHERE CLAUSES*
> > IF check1 THEN SQL = SQL & " age BETWEEN 1 AND 5 AND"
> > IF check2 THEN SQL = SQL & " age BETWEEN 6 AND 9 AND"
> > IF check3 THEN SQL = SQL & " age BETWEEN 10 AND 15 AND"
> > 
> > *TRIM THE UNUSED AND STATEMENT
> > SQL = left(sql, len(SQL) - 3)
> > 
> > Add some GROUP and ORDER and LIMIT clauses as needed and send the
> > resulting string to the server.
> > 
> > Regards,
> > Mike Hillyer
> > www.vbmysql.com
> > 
> > > -----Original Message-----
> > > From: vernon [mailto:[EMAIL PROTECTED] 
> > > Sent: Thursday, June 19, 2003 12:53 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: Complex SQL involving 10 checkboxes
> > > 
> > > 
> > > I'm trying to setup a SQL statement that involes using 10 
> different 
> > > checkboxes. The checkboxes repersent age groups that I need 
> > > to forward to an 
> > > SQL statement. What would be the easiest way to do this? 
> > > 
> > > As I think this through I'm thinking I have to check it 1 and 
> > > 2 are checked 
> > > and not 3-9 and so forth which can drive a person to drink 
> > > espically when I 
> > > have other SQL statemenst I need to add to it as well.
> > > 
> > > Any ideas on the best way to do this? I have this whole thing 
> > > I was going to 
> > > post to the list but figured I start out with the basic 
> > > question first.
> > > 
> > > Thanks
> > > 
> > > -- 
> > > MySQL General Mailing List
> > > For list archives: http://lists.mysql.com/mysql
> > > To unsubscribe:    
> > > http://lists.mysql.com/mysql?> [EMAIL PROTECTED]
> > > 
> > >
> ------- End of Original Message -------
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    
> http://lists.mysql.com/mysql?> [EMAIL PROTECTED]
> 
> 

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to