Jump to content

checkbox validation


rubing

Recommended Posts

I have an html form which is submitted as a user profile.  The form has a hobbies section where the user can  select all their hobbies using html 'checkbox'. 

 

I'm trying to figure out the best way to process this info, since i might want to restrict news and updates from my site to people with certain hobbies later on.

 

Currently all the hobby info comes from a checkbox array (e.g.  <input name=hobbies[] ...),

 

I guess I should just convert the array to a string and insert it into a collumn on the users' record?  And then later when i want to SELECT people with certain hobbies just use the %LIKE% keyword?

 

Does this seem like a reasonable way to go about it?  Thanks for the help brothas and sistas. 

Link to comment
https://forums.phpfreaks.com/topic/100476-checkbox-validation/
Share on other sites

Usually, for something you're going to be querying against later, you would want to have a joining table that has the individual hobby interests in it:

 

Users:

user_id

username

etc...

 

Hobbies:

hobby_id

title

description

etc...

 

User_Hobbies:

user_id

hobby_id

 

With that kind of table structure, you could pull all users with a specific interest by just doing a query on the hobby index in the User_Hobbies table. This is much less intensive than using a LIKE on a text column since it won't require a full table scan to complete (especially if it's indexed correctly). In addition, your table structure is more normalized, too ;-)

Link to comment
https://forums.phpfreaks.com/topic/100476-checkbox-validation/#findComment-513811
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.