sql - MySQL Query for retrieving records with HTML form Checkboxes -


this question has answer here:

i everyone, i'm little bit stuck following.

i have html form checkboxes.

 <input type="checkbox" name="colors" value="1"/>1 brown<br>  <input type="checkbox" name="colors" value="2"/>2 blue<br>  <input type="checkbox" name="colors" value="3"/>3 green<br>  <input type="checkbox" name="colors" value="4"/>4 red<br>  <input type="checkbox" name="colors" value="5"/>5 yellow<br> 

i have mysql table below :

 |id|colorids|  +--+--------+  |1 |4       |  |2 |2       |  |3 |3,1     |  |4 |1       |  |5 |2,3     |  |6 |5       |   colorids type varchar 

when select box '1 brown' should result id 4, no problem. or box '1 brown' , '5 yellow', id 4 , id 6, no problem.

but when select boxes '2 blue' , '3 green' , '5 yellow' want result : id 2, id 3, id 5, id 6

now don't know how do.

if there 1 value in colorids, query works fine.

    <cfquery name="qgetcolors" datasource="#application.dsn#">             select *                                 colors                                         colorids in (#form.colors#);     </cfquery> 

what query should use want when there multiple boxes selected , more 1 value in de colorids column?

would need use 'find_in_set'? if how query form list 'colors'?

many or directions. i'm using coldfusion, query issue.

as @matt busche said, want table, this;

|id|other_id|colorids| +--+--------+--------+ |1 |1       |4 |2 |2       |2 |3 |3       |3 |4 |3       |1 |5 |4       |1 |6 |5       |2 |7 |5       |3 |8 |6       |5 

then can select other_id colourids in (<cfqueryparam value="#form.colors#" cfsqltype="cf_sql_integer" list="yes">) linking other_id id in original table

the cfqueryparam helps protect against sql injection


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -