searching data using checkboxes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

searching data using checkboxes

Post by glennn.php »

have values in two fields i want searched: *Pulmonary Pathology*Renal Pathology* (table.specialty) and *Chemical Pathology*Hematopathology* (table.subspecialty)

I'm trying to search these two fields using a large number of checkboxes using

Code: Select all

 
$checkbox1 = $_POST['specialty']; 
$string1 = '*'.@implode('*',$checkbox1).'*';
 
$checkbox2 = $_POST['subspecialty']; 
$string2 = '*'.@implode('*',$checkbox2).'*';
 
 
$sql="SELECT * FROM $tbl_user WHERE specialty LIKE '%$string1%' OR subspecialty LIKE '%$string2%' ORDER BY contact_name ASC";
 
 
 
if i search JUST Pulmonary Pathology or JUST Hematopathology i get my results, but if i search with terms that are NOT in the fields (Molecular Diagnostics) I get NO results.


Can someone show me how to get SOME of the data that's in a field using checkboxes... PLEASE? i've been on this all day...

my inputs look like:

<LI><INPUT type="checkbox" name="subspecialty[]" value="Chemical Pathology">Chemical Pathology
<LI><INPUT type="checkbox" name="subspecialty[]" value="Hematopathology">Hematopathology



Please help?
Thanks
GN
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: searching data using checkboxes

Post by aceconcepts »

The checkboxes you are posting from your forms are posting as arrays - this is correct.

However, you are not handling them as array in your PHP script.

To get the values from these arrays you could use a foreach loop:

Code: Select all

 
foreach($checkbox1 as $chk1)
{
//GET EACH INDIVIDUAL VALUE FROM HERE
}
 
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Re: searching data using checkboxes

Post by glennn.php »

awesome - thanks!
Post Reply