So, I have two queries which will pull out data from the database. However, I need to use these data to get the array difference by using php. I want to send both employeeName and designation into an array and then get the difference. The below code I have used does not work as expected. Any solution for this matter ?
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include_once 'config.php';
$sql1 = "SELECT employeeName, designation FROM t2o_mappings WHERE type = '". $_GET['type'] ."' AND employeeCompany = '".$_GET['employeeCompany']."'"; //System Data;
$sql2 = "SELECT employeeName, designation FROM mappings_view WHERE uNo = '" . $_GET['uNo'] . "' AND uCompany = '" . $_GET['uCompany'] . "' AND type = '". $_GET['type'] ."' AND employeeCompany = '".$_GET['employeeCompany']."'"; //App Data;
//WHERE uNo = '".$_GET['uNo']."' AND uCompany = '".$_GET['uCompany']."'
$result1 = sqlsrv_query($conn, $sql1);
$result2 = sqlsrv_query($conn, $sql2);
$row1 = [];
$row2 = [];
while ($rs1 = sqlsrv_fetch_array($result1, SQLSRV_FETCH_ASSOC)) {
$row1[] = $rs1['employeeName, designation'];
}
while ($rs2 = sqlsrv_fetch_array($result2, SQLSRV_FETCH_ASSOC)) {
$row2[] = $rs2['employeeName, designation'];
}
print_r($row1);
print_r($row2);
$HaveSysNoApp = array_diff($row1, $row2); //Have in System, Not in App
$HaveAppNoSys = array_diff($row2, $row1); //Have in App, Not in System
echo 'HaveSysNoApp';
print_r($HaveSysNoApp);
echo '$HaveAppNoSys';
print_r($HaveAppNoSys);
?>