-1
because this query is returning me all the elements of the table offer_pro I want and only the table id offers?
is not taking the elements title, description, value, user_of, categ, location, fav, table offers
$cmd="SELECT
ofertas.id,
ofertas.titulo,
ofertas.descricao,
ofertas.valor,
ofertas.user_of,
ofertas.categ,
ofertas.local,
ofertas.fav,
favoritos.id_oferta,
ofertas_pro.id,
ofertas_pro.titulo,
ofertas_pro.descricao,
ofertas_pro.valor,
ofertas_pro.user_of,
ofertas_pro.categ,
ofertas_pro.local,
ofertas_pro.fav
FROM favoritos
LEFT JOIN ofertas ON (ofertas.id=favoritos.id_oferta)
LEFT JOIN ofertas_pro ON (ofertas_pro.id=favoritos.id_oferta)";
I tried removing the reserved variable "location" but the problem continues. I only get the field id from the offers. It this way does not take the rest of the data The complete code is this:
$cmd="SELECT
ofertas.id,
ofertas.titulo,
ofertas.descricao,
ofertas.valor,
ofertas.user_of,
ofertas.categ,
ofertas.local,
ofertas.fav,
favoritos.id_oferta,
ofertas_pro.id,
ofertas_pro.titulo,
ofertas_pro.descricao,
ofertas_pro.valor,
ofertas_pro.user_of,
ofertas_pro.categ,
ofertas_pro.local,
ofertas_pro.fav
FROM favoritos
LEFT JOIN ofertas ON (ofertas.id=favoritos.id_oferta)
LEFT JOIN ofertas_pro ON (ofertas_pro.id=favoritos.id_oferta)";
//ORDER BY f.id_user='$login_session'";*/???
$produtos = mysql_query($cmd);
$total = mysql_num_rows($produtos);
//exibe os produtos
echo "<table style= width:auto>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Empresa</th>";
echo "<th>Categoria</th>";
echo "<th>Serviço</th>";
echo "<th>Descrição</th>";
echo "<th>Pagamento</th>";
echo "<th>Distrito</th>";
echo "<th>Ações</th>";
echo "<th>Avaliar</th>";
echo "<th>Total</th>";
echo "</tr>";
while ($produto = mysql_fetch_array($produtos)) {
echo "<tr>";
echo "<td>".$produto['id_oferta']."</td>";
echo "<td>autor:".$produto['user_of'] . "</td>";
echo "<td>".$produto['categ'] . "</td>";
echo "<td>".$produto['titulo'] . "</td>";
echo "<td>".$produto['descricao'] . "</td>";
echo "<td>".$produto['valor'] . "</td>";
echo "<td>".$produto['local'] . "</td>";
echo "<td><a href=aceita.php?id=".$produto['id'].">Aceitar</a></td>";
echo "<td><a href=fav.php?id=".$produto['id']."><img src='img/fav.png' height='24' width='24'></a></td>";
echo "<td>".$produto['fav'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
It is very strange LEFT JOIN with two other identical tables. If you run this query with INNER JOIN, it would give the same result if it is as you say (that the corresponding rows in the tables exist), which happens?
– epx
I don’t get anything from the comic.. = / any idea?
– David Concha
Would have to be missing the id in the table offers, which exists in the other two (offers_pro and favorites).
– epx
12 If I replace the offers_pro by offers and where are the offers replace by offers_pro, it runs the offers and leaves the offers_pro.
– David Concha
offers_pro.local the word "local" is a reserved SQL variable.
– Ivan Ferrer
If you have a new question, ask it by clicking the button Ask question. Include a link to this question if it helps provide context.
– Ricardo
I simulated the tables and the command here and it worked (I created only the key and one more field, not all, but it would be enough to catch some problem in SQL).
– epx
What database is this in? I used Mysql to test.
– epx
I recommend replacing mysql_* with mysqli_*, as it will soon be discontinued.
– Ivan Ferrer