2
Good afternoon guys. I have a problem that I don’t know how to solve anymore.
I have the following mysql query in php:
mysql_select_db("banco", $conexao);
$resultado = mysql_query("SELECT * FROM pessoa WHERE id = '" . $cod . "'");
while ($linha = mysql_fetch_array($resultado))
It works.
But I need to get the data from another table referenced in the person table. Table person has a column with foreign key of vehicle table.
If I put sql below in Phpmyadmin to test, it works :
SELECT p.id, p.nome, v.modelo FROM pessoa p
INNER JOIN veiculo v ON p.veiculo = v.id
WHERE p.id = 17
Now if I take this sql and put in php gives error:
mysql_select_db("banco", $conexao);
$resultado = mysql_query("SELECT p.id, p.nome, v.modelo FROM pessoa p INNER JOIN veiculo v ON p.veiculo = v.id WHERE p.id = '" . $cod . "'");
while ($linha = mysql_fetch_array($resultado))
It’s already consumed my day! What can I be missing?
What’s the mistake that comes?
– Sergio
Shouldn’t be
INNER JOIN veiculo AS v? there is one missingASand the same inFROM pessoa pwhich should beFROM pessoa AS p– Sergio
The alias, depending on the Mysql version, can be referenced without the term AS. But particularly I don’t see it as good practice.
– Daniel Omine
Thanks for the tips!
– Marcia Pereira Reis