1
I am making a section on my site called "My Ideal Board", in it the user inserts his data (weight, height, etc), a comparison is made in the bank (join
) and is returned to the user the ideal board type according to his profile.
I have a table with reference of all sizes and types of board according to height, weight and user experience.
I’m doing it this way:
I divided it into two tables:
- Table dados_usuario
, obviously, stores user data(Experience, height and weight);
- Table prancha
has the reference values (type, size, weight and litragem) on each board according to experience, weight, user height.
-> I compare the table dados_usuario
with the table prancha
and return to the user the ideal model. How to do this?
At first I thought to put the same fields both in the table dados_usuario
how much in the table prancha
, make a inner join
and have the data I want.
However, the two tables would have duplicated values.
`dados_usuario` `prancha`
altura2 peso2
altura2 peso2
altura2 peso2
altura1 peso1
altura1 peso1
altura1 peso1
comparo e exibo...
I believe that this is not good practice nor the best way to do it. I know there are other methods of doing this.
The point is, how best to compare these data?
How to identify which line is compatible with the data the user will enter?
My bank:
CREATE TABLE DADOS_USUARIO(
usuario INT NOT NULL AUTO_INCREMENT,
nome VARCHAR(150) not null,
email VARCHAR(50) not null,
estilo VARCHAR(14) not null,
exp VARCHAR(13) not null,
altura VARCHAR(12) not null,
peso VARCHAR(9) not null,
PRIMARY KEY(usuario)
);
CREATE TABLE PRANCHA(
prancha_pri INT NOT NULL AUTO_INCREMENT,
tipo_prancha VARCHAR(9) NOT NULL,
tamanho_prancha VARCHAR(9) not null,
meio_prancha VARCHAR(12) not null,
litragem_prancha VARCHAR(8) not null,
PRIMARY KEY (prancha_pri)
);
DATA ENTRY IN DADOS_USUARIO TABLE':
INSERT INTO EXPERIENCIA VALUES (NULL, 'joao', '[email protected]', 'Surf', 'INICIANTE', '<1,60m', '>90kg');
INSERT INTO EXPERIENCIA VALUES (NULL, 'john', '[email protected]', 'StandUP Paddle', 'INTERMEDIARIO', '1,81 - 1,90m', '81 - 90kg');
INSERT INTO EXPERIENCIA VALUES (NULL, 'carl', '[email protected]', 'Surf', 'AVANÇADO', '>1,90m', '71 - 80kg');
TABLE ENTRY OF DATA PRANCHA
:
INSERT INTO PRANCHA VALUES (1, 'FUN', '8', '21 polegadas', '43L');
INSERT INTO PRANCHA VALUES (2, 'FUN', '8.8', '21 polegadas', '43L');
INSERT INTO PRANCHA VALUES (3, 'LONGBOARD', '9.2', '21 polegadas', '55L');
INSERT INTO PRANCHA VALUES (4, 'PRANCHA', '5.5 a 5.8', '20 polegadas', '30L');
INSERT INTO PRANCHA VALUES (5, 'PRANCHA', '5.5 a 5.10', '20 polegadas', '30L');
INSERT INTO PRANCHA VALUES (6, 'PRANCHA', '5.9 a 6.0', '21 polegadas', '32L');
INSERT INTO PRANCHA VALUES (7, 'PRANCHA', '6.0 a 6.4', '21 polegadas', '34L');
INSERT INTO PRANCHA VALUES (8, 'PRANCHA', '5.10 a 6.4', '20 polegadas', '30L');
INSERT INTO PRANCHA VALUES (9, 'PRANCHA', '5.10 a 6.4', '20 polegadas', '32L');
INSERT INTO PRANCHA VALUES (10, 'PRANCHA', '6.2 a 6.6', '21 polegadas', '32L');
INSERT INTO PRANCHA VALUES (11, 'PRANCHA', '6.4 a 6.8', '21 polegadas', '34L');
INSERT INTO PRANCHA VALUES (12, 'PRANCHA', '6.2 a 6.6', '20 polegadas', '30L');
INSERT INTO PRANCHA VALUES (13, 'PRANCHA', '6.2 a 6.6', '21 polegadas', '30L');
INSERT INTO PRANCHA VALUES (14, 'PRANCHA', '6.2 a 6.6', '21 polegadas', '34L');
INSERT INTO PRANCHA VALUES (15, 'PRANCHA', '6.2 a 6.6', '21 polegadas', '36L');
INSERT INTO PRANCHA VALUES (16, 'PRANCHA', '6.2 a 6.6', '21 polegadas', '38L');
INSERT INTO PRANCHA VALUES (17, 'PRANCHA', '6.2 a 7.0', '21 polegadas', '34L');
INSERT INTO PRANCHA VALUES (18, 'PRANCHA', '6.2 a 7.0', '21 polegadas', '38L');
INSERT INTO PRANCHA VALUES (19, 'PRANCHA', '5.5 a 5.8', '18 polegadas', '23L');
INSERT INTO PRANCHA VALUES (20, 'PRANCHA', '5.8 a 5.10', '18 polegadas', '24L');
INSERT INTO PRANCHA VALUES (21, 'PRANCHA', '5.10', '18 polegadas', '27L');
INSERT INTO PRANCHA VALUES (22, 'PRANCHA', '6.0 a 6.2', '19 polegadas', '28L');
INSERT INTO PRANCHA VALUES (23, 'PRANCHA', '6.0 a 6.2', '19 polegadas', '29 a 31L');
INSERT INTO PRANCHA VALUES (24, 'PRANCHA', '5.10 a 6.0', '19 polegadas', '24L');
INSERT INTO PRANCHA VALUES (25, 'PRANCHA', '5.10', '19 polegadas', '26L');
INSERT INTO PRANCHA VALUES (26, 'PRANCHA', '6.0', '19 polegadas', '27L');
INSERT INTO PRANCHA VALUES (27, 'PRANCHA', '6.0', '19 polegadas', '29L');
INSERT INTO PRANCHA VALUES (28, 'PRANCHA', '6.2', '20 polegadas', '30 a 31L');
INSERT INTO PRANCHA VALUES (29, 'PRANCHA', '6.0', '19 polegadas', '25L');
INSERT INTO PRANCHA VALUES (30, 'PRANCHA', '6.0', '19 polegadas', '28L');
INSERT INTO PRANCHA VALUES (31, 'PRANCHA', '6.0', '19 polegadas', '30L');
INSERT INTO PRANCHA VALUES (32, 'PRANCHA', '6.0 a 6.2', '20 polegadas', '30 a 31L');
INSERT INTO PRANCHA VALUES (33, 'PRANCHA', '5.11', '19 polegadas', '26L');
INSERT INTO PRANCHA VALUES (34, 'PRANCHA', '5.11', '19 polegadas', '28L');
INSERT INTO PRANCHA VALUES (35, 'PRANCHA', '6.0', '20 polegadas', '29L');
INSERT INTO PRANCHA VALUES (36, 'PRANCHA', '6.1', '20 polegadas', '30L');
INSERT INTO PRANCHA VALUES (37, 'PRANCHA', '6.1 a 6.6', '20 polegadas', '30 a 31L');
INSERT INTO PRANCHA VALUES (38, 'PRANCHA', '6.1', '19 polegadas', '27L');
INSERT INTO PRANCHA VALUES (39, 'PRANCHA', '6.1', '19 polegadas', '28L');
INSERT INTO PRANCHA VALUES (40, 'PRANCHA', '6.1 a 6.3', '20 polegadas', '29L');
INSERT INTO PRANCHA VALUES (41, 'PRANCHA', '6.1 a 6.4', '20 polegadas', '31L');
INSERT INTO PRANCHA VALUES (42, 'PRANCHA', '6.2 a 6.6', '20 polegadas', '31L');
In my form, are all the values of height and weight. Visually he puts the exact height and weight of it. However, in value
of the fields I placed the values of my table:
Height:
<option value="1,71 - 1,80m">1.71m</option>
<option value="1,71 - 1,80m">1.72m</option>
<option value="1,71 - 1,80m">1.73m</option>
<option value="1,71 - 1,80m">1.74m</option>
<option value="1,71 - 1,80m">1.75m</option>
<option value="1,71 - 1,80m">1.76m</option>
Heaviness:
<option value="81 - 90kg">88Kg</option>
<option value="81 - 90kg">89Kg</option>
<option value="81 - 90kg">90Kg</option>
<option value=">90kg">91Kg</option>
<option value=">90kg">92Kg</option>
<option value=">90kg">93Kg</option>
<option value=">90kg">94Kg</option>
MY JOIN:
SELECT USU.nome,
USU.exp,
USU.altura,
USU.peso,
PRAN.tipo_prancha,
PRAN.tamanho_prancha,
PRAN.meio_prancha,
PRAN.litragem_prancha
FROM DADOS_USUARIO AS USU
INNER JOIN PRANCHA AS PRAN
ON(USU.usuario = PRAN.prancha_pri);
The question of the height and weight range is no problem. As I put in the post, visually the user inserts their exact height and weight. Ex: Pedro, 1.85, 79Kg. But I save the
value
from the field and within thevalue
i put the tracks that are on my reference table. It’s right at the end of the post.– Zkk
My problem is to cross the user’s data with the reference table. Ex: João, Surf, Intermediario, >1.60 - 1.70m, <60kg. <- João’s data
– Zkk
Looking at the reference table, the
prancha ideal
for Joao is the typePRANCHA
,6.4 a 6.8
,21 polegadas
and34 litros
.– Zkk
How can I make this comparison, do you understand? Compare John’s data with the table
prancha
. And return the equivalent line.– Zkk
As in the select I passed you I am comparing the height of the user to the maximum of the board. In this list you can add all the comparatives you want between the fields of the table and the table user.
– Reginaldo Rigo