I have a query that looks for information from two different tables, with two conditions. Apparently it worked fine, but when the a.vendedor
field is empty, the result is null.
I understand that the result should be the same, but I would like to know if I can (by changing the query) return the other lines of SELECT , excluding b.nome
when a.vendedor=b.codigo
for false.
I already tried to use OR
instead of AND
, but the result is not what I expected.
Normal result:
[
{
descricao: "1",
cliente: "José Paulo Rodrigues",
local: "Mesa 1",
nome: "Armando Azevedo"
}
]
"Expected" result when a.vendedor
is empty (when a.vendedor = b.codigo
is not true):
[
{
descricao: "1",
cliente: "José Paulo Rodrigues",
local: "Mesa 1",
nome: "0"
}
]
My code:
$codigo = $_GET['cod'];
$sqlcode = mysql_query("SELECT a.descricao, a.cliente, a.local, b.nome
FROM terminal_cartao a, funcionarionew b
WHERE descricao='$codigo' AND a.vendedor=b.codigo");
while($result=mysql_fetch_object($sqlcode))
{
$jsonObj[] = $result;
}
$final_res = json_encode($jsonObj);