I have these code to pull data from two different database.
And I need to eliminate the same row by 'staffid'.
So far I can eliminate the duplicate. But the output is not what I want it to be.
index.php
<?php
// PART A
require 'conn.php';
$query = "SELECT STAFFID FROM TABLE";
$result = oci_parse($conn, $query);
oci_execute($result);
while ($row = oci_fetch_array($result,OCI_NUM)){
$arr[] = $row[0];
}
// PART B
$url="http://localhost/fetch_data.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
foreach(json_decode($result) as $result2)
{
if(!in_array($result2[0],$arr))
{
$total = "".$result2[0].",".$result2[1].",".$result2[2]."<br/>";
echo json_encode($total);
}
}
?>
The output for far for the above code as below
"A001","BILLY","[email protected]"
"A002","JOHN","[email protected]"
"A003","SALLY","[email protected]"
fetch.php
<?php
include_once('conn.php');
$arr = array();
$query = "SELECT * FROM TABLE ";
$stmt = sqlsrv_prepare($conn, $query);
$result = sqlsrv_execute($stmt);
$row = sqlsrv_fetch_array($stmt);
$array = array();
while( $self = sqlsrv_fetch_array( $stmt)) {
$array2 = array();
$array2[]= $self['ID'];
$array2[]= $self['NAME'];
$array2[]= $self['EMAIL'];
$array[] = $array2;
}
echo json_encode($array);
?>
My goal is to change it into JSON as below. I'm missing the bracket and the coma.
[
["A001","BILLY","[email protected]"],
["A002","JOHN","[email protected]"],
["A003","SALLY","[email protected]"]
]
Appreciate if someone can help me to fix this issue. Thanks.
index.phpright?