0
I am trying to make a report by joining 3 tables. But the table is not being generated. The query works in PHPMYADMIN, but not in php.
PHP code
$sql = "SELECT fp_marca.marca as MarcaF,
fp_modelo.modelo as ModeloF,
fp_ano.combustivel as CombustivelF,
fp_ano.ano as AnoF,
fp_ano.valor as ValorF
FROM fp_ano
LEFT JOIN fp_modelo on fp_ano.codigo_modelo = fp_modelo.codigo_modelo
LEFT JOIN fp_marca on fp_modelo.codigo_marca = fp_marca.codigo_marca
ORDER BY fp_ano.codigo_fipe, fp_ano.ano";
$result = mysqli_query($sql) or die("error in query");
while ($row = mysql_fetch_array($result)) {
echo "<tr>
<td>" . $row['marca'] . "</td>
<td>" . $row['modelo'] . "</td>
<td>" . $row['combustivel'] . "</td>
<td>" . $row['ano'] . "</td>
<td>" . $row['valor'] . "</td>
</tr>";
}
Response to the Code
error in query
In one query you used mysql-i- and in the other mysql. Isn’t that right? $result = mysqli_query($sql) or die("error in query"); [mysqli] while ($Row = mysql_fetch_array($result)) [mysql]
– Vítor André
I made the correction, the query stopped giving the error, but not yet displaying the list, the page is empty.
– Davi R Rossini
Using var_dump it gives some information? Try to give an echo $Row['Modelof'] and see if it comes out.
– Vítor André
No result. Blank page
– Davi R Rossini
Dude, it’s hard without having the database to test. My knowledge isn’t too great to look at and tell you what might be locking. Of the two: send me the tables or look at this tutorial - http://blog.thiagobelem.net/relations-tabelas-no-mysql
– Vítor André