0

I have 20 checkboxes on a form on my website, I need to select between 1-3. but u can have say

1, 2 and 3 or 4, 5 and 1

once the user has selected which checkboxes he wants it search the database for the appropriate answer based on what they have selected.

my thought was to have 'IF' statements but that mean i would have loads.

Any other way around it?

 if ((!empty($1)))
  { 
  $sql= "SELECT * FROM db WHERE db.category 
  LIKE CONVERT( _utf8 '%1%' USING latin1 ) COLLATE latin1_swedish_ci $limit "; 
  $result = mysql_query($sql); 
  }
   else if ((!empty($1)) && (!empty($2))) { 
  $sql= "SELECT * FROM db WHERE db.category 
  LIKE CONVERT( _utf8 '%1%' USING latin1 ) COLLATE latin1_swedish_ci 
  AND db.category LIKE CONVERT( _utf8 '%2%' USING latin1 ) 
  COLLATE latin1_swedish_ci $limit "; $result = mysql_query($sql); 

}

user2081357
  • 63
  • 1
  • 2
  • 6
  • You will need to control the Client-side with JavaScript and then on submitting the form (or using live AJAX) you have to revalidate the input again server-side in PHP. –  Feb 17 '13 at 22:39
  • "loads" what kind of loads? counting how many selected checkboxes there are wouldn't produce a "load" unless you're running your browser on an 8088-4.77mhz machine. – Marc B Feb 17 '13 at 23:17

2 Answers2

0

if you have checkbox array you can use foreach cycle iterate through all checked checkboxes. You should give some html o be more specific what does your checkbox values hold. Try reading: Get $_POST from multiple checkboxes

Community
  • 1
  • 1
insanebits
  • 818
  • 1
  • 6
  • 24
  • if ((!empty($1))) { $sql= "SELECT * FROM db WHERE db.category LIKE CONVERT( _utf8 '%1%' USING latin1 ) COLLATE latin1_swedish_ci $limit "; $result = mysql_query($sql); } else if ((!empty($1)) && (!empty($2))) { $sql= "SELECT * FROM db WHERE db.category LIKE CONVERT( _utf8 '%1%' USING latin1 ) COLLATE latin1_swedish_ci AND db.category LIKE CONVERT( _utf8 '%2%' USING latin1 ) COLLATE latin1_swedish_ci $limit "; $result = mysql_query($sql); } – user2081357 Feb 17 '13 at 22:52
  • You should edit your question appending this code because it's difficult to read code without indentation. – insanebits Feb 17 '13 at 22:54
0

Working with DOM in JavaScript, it is not that hard.

Also, you will find info about checkboxes over here

sybear
  • 7,837
  • 1
  • 22
  • 38