glennn.php Posted April 4, 2008 Share Posted April 4, 2008 given a Job Posting/Job Search script... i have an array of checkboxes (Surgery, Optometry, Dentistry, etc...) that are imploded into an array of data and inserted into a table.field as part of a Job Posting. $checkbox1 = $_POST['specialty']; $string1 = implode($checkbox1,", "); $checkbox2 = $_POST['subspecialty']; $string2 = implode($checkbox2,", "); $sql="INSERT INTO $tbl_user (username, password, specialty, subspecialty) VALUES (\"$_POST[username]\", \"$_POST[password]\", \"$string1\", \"$string2\")"; for the Job Search, i have the same array of checkboxes, of course, and i need to check the selected checkboxes against the database and return just the records that contain a particular value (Surgery, Dentistry, for instance)... i know to do this: $sql="SELECT * FROM $tbl_user WHERE specialty CONTAINS ($string1)"; but i don't know how to get the selected values into the Search query... does that make sense? appreciate any help! GN Quote Link to comment Share on other sites More sharing options...
drewbee Posted April 4, 2008 Share Posted April 4, 2008 Hi Glenn. You need to learn to normalize your data. You should not be storing the specialties in the main table, but creating a child table for this. ie specialty_id, job_id, specialty_name. That way if you wanted to get the specialtyies of a job... select specialty_name from specialties where job_id = 'job_id' Quote Link to comment Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 thanks drewbee - well, i'm only looking for ALL records that would contain ANY of the selected checkboxes, not where job_id = 'job_id'... i tried this that works to an extent: $checkbox1 = $_POST['specialty']; // if ($checkbox1 != '') { $string1 = implode($checkbox1,", "); // } else { // $string1 = 'null'; // } $checkbox2 = $_POST['subspecialty']; // if ($checkbox2 != '') { $string2 = implode($checkbox2,", "); // } else { // $string2 = 'null'; // } $sql="SELECT * FROM $tbl_user WHERE specialty LIKE '%$string1%' OR subspecialty LIKE '%$string2%' ORDER BY contact_name ASC"; but it doesn't always work... i'm not always getting a record that contains a term that IS checked, and sometimes it returns ALL records that don't match... ANY help? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.