0
MY BANK
CREATE TABLE EXPERIENCIA(
exp_pri INT NOT NULL AUTO_INCREMENT,
nome VARCHAR(150),
email VARCHAR(50),
exp VARCHAR(100),
PRIMARY KEY(exp_pri)
);
CREATE TABLE PRANCHA(
prancha_pri INT NOT NULL AUTO_INCREMENT,
tamanho_prancha VARCHAR(8),
meio_prancha VARCHAR(2),
litragem_prancha VARCHAR(3),
PRIMARY KEY (prancha_pri)
);
CREATE TABLE ALTURAPESOESTILO(
idAltPes INT NOT NULL AUTO_INCREMENT,
idExp INT,
idPrancha INT,
altura VARCHAR(4),
peso VARCHAR(3),
estilo VARCHAR(15),
primary key (idAltPes),
constraint fk_idExp foreign key (idExp) references EXPERIENCIA (exp_pri),
constraint fk_idPrancha foreign key (idPrancha) references PRANCHA (prancha_pri)
);
MY SQL:
$query = "SELECT EXP.exp,
AEP.altura,
AEP.peso,
AEP.estilo,
PRAN.tamanho_prancha,
PRAN.meio_prancha,
PRAN.litragem_prancha
FROM EXPERIENCIA AS EXP
INNER JOIN ALTURAPESOESTILO AS AEP
ON (EXP.exp_pri = AEP.idAltPes)
INNER JOIN PRANCHA AS PRAN
ON (PRAN.prancha_pri = AEP.idAltPes)";
$resultado = mysqli_query($conexao,$query);
$retorno = array();
while($experiencia = mysqli_fetch_assoc($resultado)){
$retorno[] = $experiencia;
}
return $retorno;
}
INDEX.PHP
include 'banco.php';
$resultado = array();
$resultado = BuscaAlgo($conexao);
foreach($resultado as $valor)
{
echo $valor['exp']; print(' '); echo $valor['altura']; print(' '); echo $valor['peso'];
echo $valor['estilo']; print(' '); echo $valor['tamanho_prancha']; print(' '); echo $valor['meio_prancha'];
print(' '); echo $valor['litragem_prancha']; ?><br> <?php
}
I am putting together three tables and trying to display them. However, when I put directly into Mysql and my code, nothing is returned. No error, but also nothing is displayed.
What can it be?
That’s exactly what it was! The problem was happening in filling out my
foreign keys
. Were returning asNull
. I modified them and solved problem, thank you!– Zkk