Re: [PHP-DB] How to process a query form with CHECKBOX Please help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



S Kumar wrote:
I have a database and one table in it deals with my
patient information. Depending on their condition I
divided their age groups into 3 categories. In my
database a table patient_data has a column age_group
and a patient can be any one of young, middle or old
category. Now the possibility is that a user can selecct 1 or 2
or all three options.


In the query form, I gave the option for a user as a
check box. The piece of html code is as below:

<DIV>Age group</DIV>
<DIV>Young<input type="checkbox" name=""
value=""></DIV>
<DIV>Middle<input type="checkbox" name=""
value=""></DIV>
<DIV>Old<input type="checkbox" name="" value=""></DIV>

Problem:
I want to capture the user options and create an SQL
statement:

> Select age_group from patient_data where age_group = > young and old ;

Young<input type="checkbox" name="agegroup[]" value="young" />
Middle<input type="checkbox" name="agegroup[]" value="middle" />
Old<input type="checkbox" name="agegroup[]" value="old" />

Then in your code:

if(!empty($_GET['agegroup']) && is_array($_GET['agegroup']))
{
  $in = "'" . implode("','",$_GET['agegroup']) . "'";
  $query = "SELECT * FROM table WHERE age_group IN ($in)";
}

Next time just post this to php-general or php-db... no need to include both of them.

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux