1
I have this query below that returns me data from two related tables. It takes all vehicle fields and all product fields with equal "id_transfer"
$cmd = "SELECT p.*, v.* FROM produtos AS p
INNER JOIN veiculos AS v
ON p.id_veiculo= v.id_veiculo where p.id_transfer = '$id_transfer' AND
v.id_transfer = '$id_transfer' AND nome LIKE '%$pesq%' ORDER by nome limit
$inicio,$registros
I’m not sure how to insert a 3rd table that doesn’t need to be related.
Would that be:
Selecione
todos tabala veiculo
todos tabela produtos
com seu id_tranfer iguais
e selecione
todos da tabela agenda_saidas
com status iguais ativo
Produto
+--------+----------------+---------------+
| id | Destino | Data |
+--------+----------------+---------------+
| 01 | Rio de Janeiro | 01/01/2015 |
| 02 | São Paulo | 01/01/2015 |
+--------+----------------+---------------+
Veiculo
+--------+----------------+---------------+
| id | Veiculo | Cor |
+--------+----------------+---------------+
| 01 | Palio | Preto |
| 02 | GOL | Branco |
+--------+----------------+---------------+
agenda_saidas
+--------+----------------+---------------+
| x1 | x2 | x3 |
+--------+----------------+---------------+
| xxx | xxx | xxx |
| xxx | xxx | xxx |
+--------+----------------+---------------+
while{
Resultado = Rio de Janeiro 01/01/2015 Palio Preto
Resultado = São Paulo 01/01/2015 GOL Branco
.....
Resultado = xxx xxx xxx
Resultado = xxx xxx xxx
.....
Se é que isso e possível..
}
I’m not in time to test something now, but in mind at the moment you can do an Inner Join of the schedule_output table and a group by schedule_output.id (because it will cross nXm).
– Luis Henrique
Just like @Luishenrique said, use a Join,
"SELECT p.*, v.* FROM produtos AS p INNER JOIN veiculos AS v ON p.id_veiculo= v.id_veiculo where p.id_transfer = '$id_transfer' AND v.id_transfer = '$id_transfer' AND nome LIKE '%$pesq%' JOIN agenda_saidas WHERE status = 'ativo' ORDER by nome limit $inicio,$registros
(I didn’t test, but I don’t know if the result will be as expected).– Rafael Withoeft
What is the list of the table scheduling with the records you want to recover?
– Papa Charlie
It didn’t work. erroo Boolean Given in /home/mrangelc/public_html/transfer.php on line 382 Warning: mysql_fetch_array() expects Parameter 1 to be Resource, Boolean Given in /home/mrangelc/public_html/files/transfer.php on line 384
– Fabio Henrique