I’m developing an auctioning website. Each auction has a lot of options, that i want to be able to filter on the front-end.
I was wondering what is best practice in handling/storing these options (mostly booleans/checkboxes).
- Is it best practice to store them all in the same row ?
- Or would it be better to store them all in one “auction_options” table?
I guess the last option is the best one..but how would a query look like to:
select all auctions that have:
- state ohio
- state utah
- some other option
I just can’t get my head around this. Is this even possible ?
EDIT –> the reply to comment field was not enough
I created 3 tables:
- auction table -> a_id | a_desc | etc
- a_options table -> a_o_id | a_o_name | a_o_value
- a_options2auction table -> id | a_id | a_o_id
when i run this query:
SELECT * FROM auctions as A
INNER JOIN a_options2auction as B ON A.a_id = B.a_id
INNER JOIN a_options as C ON B.a_o_id = C.id
WHERE c.value = ‘groningen’ OR c.value = ‘utrecht’
it returns 2 rows that are both the same auction, that should not be possible 🙂
You can use an
optionstable that is connected M-N to theauctionstable.Between these two tables you should build another table to connect them.
So a query would be like this
This solutions allow you to add infinites options to an auction and store their value (each auction can have different options from the others too)