MySQL query for multiple checkbox values

user2193632

I'm new to checkboxes. I want to let users do a search based on three possible filters represented by checkbox lists. For example, if I used the form below, I'd like the user to be able to include all shapes that are (red or blue) and large. The advice I've been able to find about checkbox queries hasn't hit this issue exactly. Is there a way I can do this with one MySQL query?

<form action="dbdquery.php" method="get">


<p>
Color:
<br/>
<input type="checkbox" name="color[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="color[]" value="Red"/> Red<br/>
<input type="checkbox" name="color[]" value="Blue"/> Blue<br/>
<input type="checkbox" name="color[]" value="Yellow"/> Yellow<br/>

</p>

<p>
Size:
<br/>
<input type="checkbox" name="size[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="size[]" value="Small"/> Small<br/>
<input type="checkbox" name="size[]" value="Medium"/> Medium<br/>
<input type="checkbox" name="size[]" value="Large"/> Large<br/>

</p>


<p>
Shape:
<br/>
<input type="checkbox" name="shape[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="shape[]" value="Round"/> Round<br/>
<input type="checkbox" name="shape[]" value="Square"/> Square<br/>
<input type="checkbox" name="shape[]" value="Irregular"/> Irregular<br/>

</p>


    <input type="submit" value="Search">

</form>
Malith Wijethunga

Try this:

Use implode function,

$colors = implode("," , $_GET['color']);

$size = implode("," , $_GET['size']);

$shape = implode("," , $_GET['shape']);

Query:

select * from table where color in ($colors) or size in ($size) or shape in ($shape);

You need to add condition to check Include all. (if user check select all the variables include all the checking values)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple values into MySQL from checkbox

From Dev

PDO Insert multiple checkbox values in Mysql

From Dev

MySQL Update query with multiple values

From Dev

Mysql join query multiple values

From Dev

Oracle APEX 5.0 - SQL query based on (multiple) checkbox values

From Dev

Changing Multiple values in MySQL with a single Query

From Dev

Mysql query sum values into multiple rows

From Dev

mysql query to combine multiple values as one

From Dev

Accepting Multiple Values In Checkbox

From Dev

I am working on checkbox filter ,i am not getting to handle multiple values of checkbox in query where cause

From Dev

add checkbox with values from query

From Dev

Multiple checkbox values handling with ReactJS

From Dev

passing multiple checkbox values to controller

From Dev

Inserting multiple checkbox values in codeigniter

From Dev

jQuery hide on checkbox multiple values

From Dev

MySQL multiple values join to one table - better query?

From Java

MySQL - UPDATE multiple rows with different values in one query

From Dev

Dynamic Mysql query & passing multiple values through `GET`

From Dev

How to search through multiple set of dataset for columns and values in mysql query

From Dev

MySQL Query: Values from multiple cells in a single cell

From Dev

Dynamic Mysql query & passing multiple values through `GET`

From Dev

MySQL query with multiple random values but sum always within a range

From Dev

Make a table with a MySQL query with multiple values in some fields

From Dev

How to get checkbox values from within a MySQL query fetch loop in PHP?

From Dev

Multiple checkbox function PHP & Mysql

From Dev

Match query with multiple values

From Dev

Echoing checkbox values to use for DELETE query is failing

From Dev

How to dynamically accumulate checkbox values in a SQL query

From Dev

MySQL query with enum values

Related Related

  1. 1

    Multiple values into MySQL from checkbox

  2. 2

    PDO Insert multiple checkbox values in Mysql

  3. 3

    MySQL Update query with multiple values

  4. 4

    Mysql join query multiple values

  5. 5

    Oracle APEX 5.0 - SQL query based on (multiple) checkbox values

  6. 6

    Changing Multiple values in MySQL with a single Query

  7. 7

    Mysql query sum values into multiple rows

  8. 8

    mysql query to combine multiple values as one

  9. 9

    Accepting Multiple Values In Checkbox

  10. 10

    I am working on checkbox filter ,i am not getting to handle multiple values of checkbox in query where cause

  11. 11

    add checkbox with values from query

  12. 12

    Multiple checkbox values handling with ReactJS

  13. 13

    passing multiple checkbox values to controller

  14. 14

    Inserting multiple checkbox values in codeigniter

  15. 15

    jQuery hide on checkbox multiple values

  16. 16

    MySQL multiple values join to one table - better query?

  17. 17

    MySQL - UPDATE multiple rows with different values in one query

  18. 18

    Dynamic Mysql query & passing multiple values through `GET`

  19. 19

    How to search through multiple set of dataset for columns and values in mysql query

  20. 20

    MySQL Query: Values from multiple cells in a single cell

  21. 21

    Dynamic Mysql query & passing multiple values through `GET`

  22. 22

    MySQL query with multiple random values but sum always within a range

  23. 23

    Make a table with a MySQL query with multiple values in some fields

  24. 24

    How to get checkbox values from within a MySQL query fetch loop in PHP?

  25. 25

    Multiple checkbox function PHP & Mysql

  26. 26

    Match query with multiple values

  27. 27

    Echoing checkbox values to use for DELETE query is failing

  28. 28

    How to dynamically accumulate checkbox values in a SQL query

  29. 29

    MySQL query with enum values

HotTag

Archive