samedi 7 mai 2016

How to storage checkbox values to a field of mysql for search?

I want to storage checkbox valus to a field.

html like this

two value selected

<input type="checkbox" value="1">invest_type1
<input type="checkbox" value="2" checked>invest_type2
<input type="checkbox" value="3" checked>invest_type3
<!-- more, but less than 20-->

mysql table dict

id
project_name
invest_types   // how to save?
// other fields

Demand

multiple select

exp. User select "invest1" and "invest2",then how to fetch that row?

Plans

  1. use bit method to storage.

    invest_type2 is 2 , pow(2,2) => 4

    invest_type2 is 3 , pow(2,3) => 8

    4+8=12,when select use invest_types & (invest_type1's pow + invest_type2's pow)

  2. add table to relate

    add table to storage invest_types with every project.

    use join and distinct when use search.

Problem & Help

  • Which plan is the best?
  • What about efficiency of plan1?

Aucun commentaire:

Enregistrer un commentaire