Save Features in BD

Asked

Viewed 117 times

4

I’m starting to work with PHP, MYSQL now and I’ve come up with a question.

I am developing a classified site, the same will have categories of vehicles, real estate, electronics, etc...

My question is as follows, the guy selects car for example, car has numerous features, as well as a mobile phone, an apartment, etc.. how can I record these features in BD?

Create a table for each type? (car, truck, apartment, cell phone...) not right?

Someone can give me a direction?

Remembering that all features are selected in a checkbox according to availability and advertising type.

Follow div with checkbox

<label class="col-sm-2 control-label">Características</label>
                <div class="col-sm-9">
                  <div class="row">
                    <div class="col-sm-3"><input type="checkbox"> Air-Bar </div>
                    <div class="col-sm-3"><input type="checkbox"> Ar-Condicionado </div>
                    <div class="col-sm-3"><input type="checkbox"> Vidros Elétricos </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-3"><input type="checkbox"> Flash </div>
                    <div class="col-sm-3"><input type="checkbox"> Câmera Frontal </div>
                    <div class="col-sm-3"><input type="checkbox"> GPS </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-3"><input type="checkbox"> Tecnologia NFC </div>
                    <div class="col-sm-3"><input type="checkbox"> Detecção Facial </div>
                    <div class="col-sm-3"><input type="checkbox"> Dual Chip </div>
                  </div>
                  <div class="row">
                    <div class="col-sm-3"><input type="checkbox"> Biometria </div>
                    <div class="col-sm-3"><input type="checkbox"> HDR </div>
                    <div class="col-sm-3"><input type="checkbox"> Extensão para Cartão de Memória </div>
                  </div>
                </div>

Thank you all.

  • The characteristics are via input or it chooses according to availability and advertising type?

  • Choose via checkbox according to availability and ad type

  • If you have a list of defined features and the user chooses the options, you just need to save the ID’s. This would not solve your case?

  • But the checkbox is manually placed in the code

  • 1

    Look there could be several ways to do what you want in my opinion. Save a single string separated by commas of the characteristics, an intermediate table ex: caracteristicas_anuncio (id_anuncio, id_caracteristica, or id_anuncio, feature_name) <- in case of saving a Tring you can make a composite key for the two fields so it does not repeat.. in order.... And one more thing, can a classifieds contain more than one category? If yes... the logic would change a little too.

2 answers

0

hello, as the other users said, you can do it in various ways, in my opinion, I kept it in a string, but in the form of code,0 and 1, example: 101 ->Air-Bar:yes, Air-Conditioning:no, Electric Windows:yes, etc, but as they said you can do it in many ways! good luck

0

Friend what you will have there is a relationship for many, I mean, N for N.

What you should do is: create a table called "vehicle", another called "characteristic" and another called "vehicle" that will have the following columns:

id_veiculo;
id_caracteristica;

So one feature can be multiple vehicles and one vehicle can have several features.

Any doubt is just research on the relationship N para N that you will understand better!

P.S.: I used vehicle as an example but it serves for anyone you want to implement: apartment, mobile phone and etc...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.