I am making a section on my site called "My Ideal Surfboard", in it the user inserts his data (weight, height, etc), a comparison is done in the database ( join
) and is returned to the user type of the ideal board 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'mdoingitthisway:
Idividedintotwotables:
-Tabledados_usuario
,ofcourse,storesuserdata(Experience,heightandweight);Home -Tableprancha
hasthereferencevalues(type,size,weightandlit-tle)oneachboardaccordingtoexperience,weight,heightoftheuser.
->Icomparethedados_usuario
tablewiththeprancha
tableandreturntheusertheidealmodel.Howtodothis?
AtfirstIthoughtI'dputthesamefields,bothinthedados_usuario
tableandintheprancha
table,makeainnerjoin
andhavethedataIwant.
However,thetwotableswouldhaveduplicatevalues.
'dados_usuario''prancha'altura2peso2altura2peso2altura2peso2altura1peso1altura1peso1altura1peso1comparoeexibo...
Idonotthinkthisisagoodpracticeorthebestwaytodoit.Iknowthereareothermethodsofdoingthis.
Thequestionis,Whatisthebestwaytocomparethisdata?
Howtoidentifywhichlineiscompatiblewiththedatathattheuserwillenter?
Mybank:
CREATETABLEDADOS_USUARIO(usuarioINTNOTNULLAUTO_INCREMENT,nomeVARCHAR(150)notnull,emailVARCHAR(50)notnull,estiloVARCHAR(14)notnull,expVARCHAR(13)notnull,alturaVARCHAR(12)notnull,pesoVARCHAR(9)notnull,PRIMARYKEY(usuario));CREATETABLEPRANCHA(prancha_priINTNOTNULLAUTO_INCREMENT,tipo_pranchaVARCHAR(9)NOTNULL,tamanho_pranchaVARCHAR(9)notnull,meio_pranchaVARCHAR(12)notnull,litragem_pranchaVARCHAR(8)notnull,PRIMARYKEY(prancha_pri));
DATAINSERTINTHE'DATA_USUARIO'TABLE:
INSERTINTOEXPERIENCIAVALUES(NULL,'joao','[email protected]','Surf','INICIANTE','<1,60m','>90kg');INSERTINTOEXPERIENCIAVALUES(NULL,'john','[email protected]','StandUPPaddle','INTERMEDIARIO','1,81-1,90m','81-90kg');INSERTINTOEXPERIENCIAVALUES(NULL,'carl','[email protected]','Surf','AVANÇADO','>1,90m','71-80kg');
DATAINSERTINTABLEPRANCHA
:
INSERTINTOPRANCHAVALUES(1,'FUN','8','21polegadas','43L');INSERTINTOPRANCHAVALUES(2,'FUN','8.8','21polegadas','43L');INSERTINTOPRANCHAVALUES(3,'LONGBOARD','9.2','21polegadas','55L');INSERTINTOPRANCHAVALUES(4,'PRANCHA','5.5a5.8','20polegadas','30L');INSERTINTOPRANCHAVALUES(5,'PRANCHA','5.5a5.10','20polegadas','30L');INSERTINTOPRANCHAVALUES(6,'PRANCHA','5.9a6.0','21polegadas','32L');INSERTINTOPRANCHAVALUES(7,'PRANCHA','6.0a6.4','21polegadas','34L');INSERTINTOPRANCHAVALUES(8,'PRANCHA','5.10a6.4','20polegadas','30L');INSERTINTOPRANCHAVALUES(9,'PRANCHA','5.10a6.4','20polegadas','32L');INSERTINTOPRANCHAVALUES(10,'PRANCHA','6.2a6.6','21polegadas','32L');INSERTINTOPRANCHAVALUES(11,'PRANCHA','6.4a6.8','21polegadas','34L');INSERTINTOPRANCHAVALUES(12,'PRANCHA','6.2a6.6','20polegadas','30L');INSERTINTOPRANCHAVALUES(13,'PRANCHA','6.2a6.6','21polegadas','30L');INSERTINTOPRANCHAVALUES(14,'PRANCHA','6.2a6.6','21polegadas','34L');INSERTINTOPRANCHAVALUES(15,'PRANCHA','6.2a6.6','21polegadas','36L');INSERTINTOPRANCHAVALUES(16,'PRANCHA','6.2a6.6','21polegadas','38L');INSERTINTOPRANCHAVALUES(17,'PRANCHA','6.2a7.0','21polegadas','34L');INSERTINTOPRANCHAVALUES(18,'PRANCHA','6.2a7.0','21polegadas','38L');INSERTINTOPRANCHAVALUES(19,'PRANCHA','5.5a5.8','18polegadas','23L');INSERTINTOPRANCHAVALUES(20,'PRANCHA','5.8a5.10','18polegadas','24L');INSERTINTOPRANCHAVALUES(21,'PRANCHA','5.10','18polegadas','27L');INSERTINTOPRANCHAVALUES(22,'PRANCHA','6.0a6.2','19polegadas','28L');INSERTINTOPRANCHAVALUES(23,'PRANCHA','6.0a6.2','19polegadas','29a31L');INSERTINTOPRANCHAVALUES(24,'PRANCHA','5.10a6.0','19polegadas','24L');INSERTINTOPRANCHAVALUES(25,'PRANCHA','5.10','19polegadas','26L');INSERTINTOPRANCHAVALUES(26,'PRANCHA','6.0','19polegadas','27L');INSERTINTOPRANCHAVALUES(27,'PRANCHA','6.0','19polegadas','29L');INSERTINTOPRANCHAVALUES(28,'PRANCHA','6.2','20polegadas','30a31L');INSERTINTOPRANCHAVALUES(29,'PRANCHA','6.0','19polegadas','25L');INSERTINTOPRANCHAVALUES(30,'PRANCHA','6.0','19polegadas','28L');INSERTINTOPRANCHAVALUES(31,'PRANCHA','6.0','19polegadas','30L');INSERTINTOPRANCHAVALUES(32,'PRANCHA','6.0a6.2','20polegadas','30a31L');INSERTINTOPRANCHAVALUES(33,'PRANCHA','5.11','19polegadas','26L');INSERTINTOPRANCHAVALUES(34,'PRANCHA','5.11','19polegadas','28L');INSERTINTOPRANCHAVALUES(35,'PRANCHA','6.0','20polegadas','29L');INSERTINTOPRANCHAVALUES(36,'PRANCHA','6.1','20polegadas','30L');INSERTINTOPRANCHAVALUES(37,'PRANCHA','6.1a6.6','20polegadas','30a31L');INSERTINTOPRANCHAVALUES(38,'PRANCHA','6.1','19polegadas','27L');INSERTINTOPRANCHAVALUES(39,'PRANCHA','6.1','19polegadas','28L');INSERTINTOPRANCHAVALUES(40,'PRANCHA','6.1a6.3','20polegadas','29L');INSERTINTOPRANCHAVALUES(41,'PRANCHA','6.1a6.4','20polegadas','31L');INSERTINTOPRANCHAVALUES(42,'PRANCHA','6.2a6.6','20polegadas','31L');
Inmyform,thereareallvaluesofheightandweight.Visuallyitputstheexactheightandweightofit.However,in%offields%Iputthevaluesinmytable:
Height:
<optionvalue="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>
Weight:
<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);