Re: Building a query string

From: Date: Thu, 04 Dec 2003 02:30:59 +0000
Subject: Re: Building a query string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-171758@lists.php.net to get a copy of this message
Ed Curtis wrote:
This list has helped me out alot and I hope it can do it one more time. I need to build a MySQL query based on 11 different options from a form. Some options will have values others will be checkboxes to say include in the query.
In addition to the other suggestions, if you're going to have a series of checkboxes (or any field) that's going to be matched against the same column in your database, you can use a little trick by making your form element an array. <input type="garage[]" value="2 car">2 Car <input type="garage[]" value="1 car">1 Car <input type="garage[]" value="None">None Then you can use this bit of PHP code to add the criteria to your query... <?php $list = "'" . implode("','",$_POST['garage']) . "'"; $criteria = " AND garage IN ($list)"; Just add $criteria to your query, now. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#171758) next »