-1
Good evening, so I’m trying to create a API, and I came across the following problem, I’m not able to group the data from my inner join
, follows the code :
<?php
$json = array();
$db = 'localhost:C:\baseking\TGA.FDB';
$username = 'SYSDBA';
$password = 'masterkey';
$con = ibase_connect($db, $username, $password);
$sql = "SELECT TTICKET.idticket, TTICKETPROD.codprd, TPRODUTO.NOMEFANTASIA, TPRODUTO.preco1, TTICKET.idcartao from tticket
inner join TTICKETPROD on (TTICKETPROD.idticket = TTICKET.IDTICKET)
inner join TPRODUTO on (TTICKETPROD.codprd = tproduto.codprd)where TTICKET.status = 'A' ";
$rc = ibase_query($con, $sql);
while ($row = ibase_fetch_object($rc)) {
// print_r($row);
// echo json_encode($row);
$json['CODPRD'][] = $row -> CODPRD;
$json['IDTICKET'][] = $row -> IDTICKET;
$json['NOMEFANTASIA'][] = $row -> NOMEFANTASIA;
$json['PRECO'][] = $row -> PRECO1;
$json['IDCARTAO'][] = $row -> IDCARTAO;
echo json_encode($json['CODPRD']);
echo json_encode($json['IDTICKET']);
echo json_encode($json['NOMEFANTASIA']);
// echo "".$json['CODPRD'];
}
/*if($json['CODPRD']){
$string = implode(",",$json['CODPRD']);
$sql = "SELECT * FROM TPRODUTO where CODPRD = '{$string}'";
$rc = ibase_query($con, $sql);
while ($row = ibase_fetch_object($rc)) {
$json['NOMEFANTASIA'][] = $row -> NOMEFANTASIA;
echo json_encode($json['NOMEFANTASIA']);
} */
ibase_free_result($rc);
ibase_close($con);
Then at the time I will see the data on the web appear as follows
["000415"][3]["000415","001607"][3,23]["000415","001607","001609"][3,23,513]["000415","001607","001609","001475"][3,23,513,558]["000415","001607","001609","001475","001328"][3,23,513,558,558]["000415","001607","001609","001475","001328","001223"][3,23,513,558,558,681]["000415","001607","001609","001475","001328","001223","000743"][3,23,513,558,558,681,714]["000415","001607","001609","001475","001328","001223","000743","000270"][3,23,513,558,558,681,714,714]["000415","001607","001609","001475","001328","001223","000743","000270","000333"][3,23,513,558,558,681,714,714,714]
Already in Firebird appears more organized:
So I’m not sure how to organize by the prevailing numbers, which is the IDCARTÃO
and IDTICKET
, there is an easier way to do this?
Thank you very much, solved my problem, now I’m breaking my head to group, but this I believe that in time I will get, hugs all good.
– Matheus Martins