How to compare bank data and display to the user

1

I'm developing a surf site. In it, there is a section called My Ideal Board.

Where the user will enter his data ( Nome , email , peso , altura and experiencia (beginner, intermediate or advanced)).

I will save this data in the database and based on user characteristics (weight, height and experience) I will say the ideal board type.

The section is already done and you are already saving the user data in the database. I received a table / reference list with all board measurements according to the height and weight of the user.

Toreturntotheidealboard,Ineedtogettheuserdataandcompareitwiththistable.

Ithoughtaboutdoingthisasfollows,

Idividedintothreetables/sections:Experiencia,PesoeAlturaandModelodeprancha.

Eachtable/sectionIwillassignanID:

Userexperience->IDa,b,c
Weight&Height->IDa,b,c,d....
BoardModel->IDa,b,c,d....

Tablewiththeuserexperience,anIDforeach.



TablewiththeUserWeightandHeightratio,anIDforeach.



Final table with templates plank an ID for each.

To get the result I will somehow compare the Experiencia table with the Peso+Altura table, generating an ID or X number that will be compared to the ID of the third table (with the Table templates) and thus obtaining the result. I do not know if the explanation was very clear, anything you can ask me.

My question is: Is this correct for me? Is this the best way to do it? In code, how can I do this?

Any kind of help is welcome!

So far I only have the code that registers the data in the database:
--I do not think the HTML of the form is very useful. If you request, I post here or Pastebin.

function cadastrar($nome,$email,$estilo,$experiencia,$altura,$peso){          //INSERE OS DADOS NO BANCO
     global $wpdb;
     // Minha tabela
    $table = 'aa_minhaprancha';

    // Inserindo os dados no array "data", responsável pelos dados a serem gravados no banco
    $data = array(
      'nome' => $nome,
      'email' => $email,
      'estilo' => $estilo,
      'experiencia' => $experiencia,
      'altura' => $altura,
      'peso' => $peso,
    );

    // run the insert
    $updated = $wpdb->insert( $table, $data );

    // Se não ocorrer o update, retorna o erro
    if ( ! $updated ) {
      $wpbb->print_error();
    }

}

The bank is on Wordpress. However, there are no problems if there is any help in MySql. I convert.

Recapping:

What do I want to do? - Show the user the ideal board template according to his profile.

How do I want / am doing? - Taking user data (Experience Level, Height, Weight and Board Type) by comparing them with my lista de referência and displaying to the user .

How can I do this?

    
asked by anonymous 12.06.2016 / 20:37

2 answers

1

For what I submitted, I believe you are looking for a response that simplifies your process.

So, I would do it like this:

  • I would create a single table with all the possibilities but by height and weight range (I explain below).

  • It would create a unique ID that would meet the user's characteristics, as follows:

    NAAAPPPTTTT

  • Where:

    N = Level experience (can have more than one digit if applicable), for example N 3 (Advanced)

    AAA = Height digits (without the punctuation, for example 1.82 would be equal to 182 . I suggest that you use numbers that indicate height ranges , eg 180 would meet heights of 1.80 and 1 , 8499 ... and 185 from 1,85 to 1,8999 ... This reduces the combinations (better are wider ranges, such as ten in ten for example)

    PPP = Weight digits, for example 96 weight would equal 096 height, I suggest doing by weight range, in this example, 96 would be 095 , as it matches the range of 95 to 99,999 strong> ... weight)

    TTTT = Type board (in this case each board must have a unique code of how many digits you need, I did with four digits) , for example, board 0324

    So, for this user the ideal board would have the following ID (with intervals of 5 in 5 for the case of height and weight):

    31800950324

    If there is a single table with these IDs properly indexed, then only the search is done.

    I hope I have helped.

        
    12.06.2016 / 22:20
    -1

    Come on. What you basically want to do is model the bench according to the surfboard data, and divide it so that they have a relationship with each other.

    For example: You have a table named client:

    CREATE TABLE CLIENTES(
         idCliente INT AUTO_INCREMENT,
         Nome VARCHAR(100),
         Sexo CHAR(1),
         PRIMARY KEY(idCliente)
    );
    

    And another table of documents:

    CREATE TABLE DOCUMENTOS(
        idDocumento INT AUTO_INCREMENT,
        idCliente INT,
        NOME_DOCUMENTO VARCHAR(100),
        VALOR_DOCUMENTO VARCHAR(200),
        idTipoDocumento INT,
        PRIMARY KEY(idDocumento)
    );
    

    And finally the Documents Type table:

    CREATE TABLE TIPO_DOCUMENTO(
        idTipoDocumento INT AUTO_INCREMENT,
        NOME_DOCUMENTO VARCHAR(100),
        PRIMARY KEY (idTipoDocumento)
    );
    

    We will now make some inserts:

    INSERT INTO CLIENTES VALUES (NULL, 'AMERICO SOUZA', 'M');
    INSERT INTO CLIENTES VALUES (NULL, 'IGOR SOUZA', 'M');
    INSERT INTO CLIENTES VALUES (NULL, 'MARIA QUITANDA', 'F');
    INSERT INTO TIPO_DOCUMENTO VALUES (NULL,'RG');
    INSERT INTO TIPO_DOCUMENTO VALUES (NULL,'CPF');
    INSERT INTO TIPO_DOCUMENTO VALUES (NULL, 'TELEFONE');
    INSERT INTO DOCUMENTOS VALUES (NULL, 1, '123456789-67', 1);
    INSERT INTO DOCUMENTOS VALUES (NULL, 2, '093.356.879-90', 2);
    INSERT INTO DOCUMENTOS VALUES (NULL, 3, '+55(11)3622-5090', 3);
    

    The bank was modeled with the 1: 1 relationship, that is, one entity can only relate to another entity. Then we can use the JOIN to join the data, since we are using the relationship.

    SELECT CLI.NOME,
       DOC.VALOR_DOCUMENTO,
       TIPO.NOME_DOCUMENTO
    FROM CLIENTES AS CLI
       INNER JOIN DOCUMENTOS AS DOC ON 
       (CLI.idCliente = DOC.idCliente)
       INNER JOIN TIPO_DOCUMENTO AS TIPO ON 
       (TIPO.idTipoDocumento = Doc.idTipoDocumento)
    

    And we have the following result:

    Ifyouwanttofiltermoreresults,youcanaddtheWHEREclauseinwhichyouwillgetbeyondthejointuples,candetermineforwhichconditionsyouwanttheresult.

    Ibelievethatwiththisexampleyoucanmoveforward.ForfurtherquestionsIsuggestgivingareadaboutSQL,JOINS,WHEREandRelationships.

    link

        
    12.06.2016 / 22:06