-2
$cria = "CREATE TABLE tb_complemento (
`com_referencia_produto` varchar(09),
`com_sequencia_produto` int(01) NOT NULL,
`com_aplicacao_produto` varchar(80),
`com_anoi_anof` varchar(30),
`com_complemento` varchar(50),
CONSTRAINT com_chave primary key(com_referencia_produto,com_sequencia_produto)
) ENGINE=MyISAM DEFAULT CHARSET=latin1";
$result_cr = mysqli_query($strcon, $cria);
Only reads the last record of the add-on table. I inserted the array, but it didn’t work.
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'/>
<title>Catálogo Thor</title>
<link rel="stylesheet" href="../css/catalog.css"/>
<script src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.elevatezoom.js"></script>
</head>
<body>
<div id="titulo">AURÉLIUS CATALOG</div>
<?php
$host = "localhost";
$dbname = "bd_thor";
$user = "root";
$senha = "";
$arquivo_pd = "tb_produtos";
$arquivo_co = "tb_complemento";
$selecao = "0";
$rfprod = "";
$approd = "";
$rows = "0";
$aplic = array();
$anoif = array();
$compl = array();
$refer = $_GET['referencia'];
$strcon = mysqli_connect($host, $user, $senha, $dbname) or die('Erro de conexão ao bd_thor');
$sql = "SELECT * FROM $arquivo_pd where pro_referencia_produto = '$refer'"
or die('Erro de selecão na tb_produtos');
$result_pd = mysqli_query($strcon,$sql) or die('Erro de consulta na tb_produtos');
while ($row = mysqli_fetch_array($result_pd)) {
$rfprod = $row['pro_referencia_produto'];
$approd = $row['pro_aplicacao_produto'];
$fmprod = $row['pro_familia'];
$cfprod = $row['pro_cofap'];
$moprod = $row['pro_monroe'];
$nkprod = $row['pro_nakata'];
$kyprod = $row['pro_kyb'];
$mtprod = $row['pro_motorcraft'];
$marca = $row['pro_marca'];
$familia = $row['pro_familia'];
$carcaca = $row['pro_carcaca'];
$caixa = $row['pro_caixa'];
$observ = $row['pro_observacoes'];
}
?>
<div class="referencia">
<span><font color="#519cf8"><?php echo "$rfprod"; ?></font></span>
<span><?php echo " - "; ?></span>
<span><?php echo "$approd"; ?></span><br><br>
</div>
<div id="imagem-item">
<img id="img_01" src="../images/small/RE38-FR.jpg" data-zoom-image="../images/large/RE38-FR.jpg"/>
<div id="gallery_01">
<a href="#" data-image="../images/small/RE38-FR.jpg" data-zoom-image="../images/large/RE38-FR.jpg">
<img id="img_01" src="../images/thumb/RE38-FR.png" />
</a>
<a href="#" data-image="../images/small/RE38-PR.jpg" data-zoom-image="../images/large/RE38-PR.jpg">
<img id="img_02" src="../images/thumb/RE38-PR.png" />
</a>
<a href="#" data-image="../images/small/RE38-PE.jpg" data-zoom-image="../images/large/RE38-PE.jpg">
<img id="img_03" src="../images/thumb/RE38-PE.png" />
</a>
<a href="#" data-image="../images/small/CAMERA-SM.jpg" data-zoom-image="../images/large/CAMERA-LG.jpg">
<img id="img_04" src="../images/thumb/camera.png" />
</a>
</div>
</div>
<div id="dados-conversao">
<div class="tit-conversao">CONVERSÃO</div>
<table style="width:100%" cellspacing=5>
<tr>
<td style=color:#f6eb8f width="20%">COFAP</td>
<td style=color:#f6eb8f width="20%">MONROE</td>
<td style=color:#f7e867 width="20%">NAKATA</td>
<td style=color:#f7e867 width="20%">KAYABA</td>
<td style=color:#f7e867>MOTORCRAFT</td>
</tr>
<tr>
<td><?php echo "$cfprod" ?></td>
<td><?php echo "$moprod" ?></td>
<td><?php echo "$nkprod" ?></td>
<td><?php echo "$kyprod" ?></td>
<td><?php echo "$mtprod" ?></td>
</tr>
</table>
</div>
<?php
$sql = "SELECT * FROM $arquivo_co where com_referencia_produto = '$refer'"
or die('Erro de selecão na tb_complemento');
$result_co = mysqli_query($strcon,$sql) or die('Erro de consulta na tb_complemento');
while ($row = mysqli_fetch_array($result_co)) {
$aplic[] = $row['com_aplicacao_produto'];
$anoif[] = $row['com_anoi_anof'];
$compl[] = $row['com_complemento'];
}
for($i = 0; $i < 20; $i++) {
if ($aplic[$i] != "") {
$rows++;
}
}
for($i = 0; $i < $rows; $i++) {
?>
<div id="dados-complemento">
<table cellspacing=5>
<tr>
<td style=color:#f6eb8f width="20%">APLICAÇÃO</td>
<td style=color:#f6eb8f width="20%">ANO</td>
<td style=color:#f7e867 width="20%">COMPLEMENTO</td>
</tr>
<tr>
<td><?php echo "$aplic[$i]" ?></td>
<td><?php echo "$anoif[$i]" ?></td>
<td><?php echo "$compl[$i]" ?></td>
</tr>
</table>
</div>
<?php
}
?>
Enter the code for analysis.
– NoobSaibot
How many records do you have on this table with the reference passed by parameter ?
– NoobSaibot
@Paulo Ladeira Inside the while vc has to pass the values to an array. Otherwise, it will always be the last value.
– Diego Schmidt
Paulo Ladeira, I believe that it is better to remake your question, so that it is not negative, several times!
– jmfrolim