0
I’m doing a query inside another in php until beauty works but the result of the query inside only returns me a line that would be the last line, plus the query had to return 3 lines so I decided to put the query result in an array and made it into json using php’s json_encode function, now I need to separate this information into strings someone knows how I can do it?
follows the code excerpt:
while (($row = oci_fetch_array($stid)) != false) {
if($row['LOTE_SERIAL'] == ""){
$buscaTotal = oci_parse($conn,"select di.docit_amt TOTAL, docit_qt QTD, di.docit_lot LOTE from DOCIT di, DOCHD dc where di.docit_doc_prc_id = dc.dochd_doc_prc_id and dc.dochd_doc_id in ('228') and di.docit_cd in ('BRR010C030')")or die("erro no select buscaTotal");
oci_execute($buscaTotal);
$total_prod = array();
$qtd = array();
$lote = array();
while (($val = oci_fetch_array($buscaTotal)) != false){
$total_prod[] = $val['TOTAL'];
$qtd[] = $val['QTD'];
$lote[] = $val['LOTE'];
}
$total = json_encode($total_prod)."<br>";
$qtd = json_encode($qtd)."<br>";
$lote = json_encode($lote)."<br>";
echo $total;
}else{
$total = $row['TOTAL_PRODUTO'];
$qtd = $row['QTD_ENTRADA'];
$lote = $row['LOTE_SERIAL'];
}
echo "<tr class='filtro'>";
echo "<td>".$row['CESV_ENTRADA']."</td>";
echo "<td>".$row['MOTIVO_ACESSO']."</td>";
echo "<td>".$row['CLIENTE']."</td>";
echo "<td>".$row['PEDIDO']."</td>";
echo "<td>".$row['DATA_ENTRADA']."</td>";
echo "<td>".$row['DATA_SAIDA']."</td>";
echo "<td>".$row['NF_ENTRADA']."</td>";
echo "<td>".$row['NF_SAIDA']."</td>";
echo "<td>".$row['PRODUTO']."</td>";
echo "<td>".$row['UNIDADE']."</td>";
echo "<td>".$lote."</td>";
echo "<td>".$row['LOTE_COMP']."</td>";
echo "<td>".$row['UZS_ENTRADA']."</td>";
echo "<td>".$row['UZS_SAIDA']."</td>";
echo "<td>".$qtd."</td>";
echo "<td>".$total."</td>";
echo "<td>".$row['PESO']."</td>";
echo "</tr>";
}
this code returns this: ["29070","3960","63000"]
and I need you to come back like this 29070 3960 63000
Does anyone have any idea how I can do this?
Edit your question, take the image and place the real code. Greetings.
– Fabiano Monteiro
Your
echo $total
, printa: ["29070","3960","63000"]? Have you tried using,json_encode($json, JSON_PRETTY_PRINT)
– Fabiano Monteiro
I tried it didn’t work
– teste
Got it. You’ve set up an array
$total_prod[] = $val['TOTAL'];
Why are you running ajson_encode($total_prod)
in it, if you at the end just want to take a print? Travels with foreach, you will have the result you are looking for.– Fabiano Monteiro
is that you needed to do outside while the print
– teste
It would be like taking duplicate values from foreach, for for I’m doing one while inside another while it’s repeating?
– teste
Did you see my answer to your question? It’s just down. Did you try to apply it? If so, make your comments on the answer below. Greetings
– Fabiano Monteiro