Welcome Guest, Not a member yet? Register   Sign In
Best Method to store a Checkbox
#1

Good morning everyone,
I have a checkbox form, where the user selects one or more options for each category. I need to save the selection made in a mysql database.

the database:

CATEGORY
id_category: INT PRIMARY AI
name: VARCHAR (30)
PRODUCT
id_product: INT PRIMARY AI
id_category INT
name: VARCHAR (30)

initially I thought of using the php implode function and saving only the indexes, separated by a dot, in the user table.

for example, if user select:
Meat (as category),
tbone and cicken (as product).
Fruit (as category),
pear, apple and cherry (as product).


i have something like: 1.3,1.15,9.5,9.18 (9 category . 18 product in this case)

at this point I would insert this string into the user table.
the moment I need to access the data, I would have to use the exoplode command twice.
one to divide the categories and one to divide the products.
with the result, I would make a query to the categories table and one to the products table.

Do you think this is a good way to approach this type of situation or is there a better way to save a series of checkboxes?
Reply


Messages In This Thread
Best Method to store a Checkbox - by elbambolo - 01-02-2024, 09:32 AM
RE: Best Method to store a Checkbox - by demyr - 01-02-2024, 02:10 PM
RE: Best Method to store a Checkbox - by demyr - 01-03-2024, 04:20 AM
RE: Best Method to store a Checkbox - by demyr - 01-07-2024, 09:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB