我正在尝试从我的选择语句中获取结果,我正在使用 2 个语句并想要 2 个输出的 JDON 响应。就这样。
问题:我正在从Chrome邮递员进行测试,它显示结果
[
null,
null
]
下面是我的php代码;我哪里出错了?
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x-requested-with');
header('Cache-Control: max-age=900');
header("Content-Type: application/json"); // tell client that we are sending json data
define("DB_USR","erSKJV");
define("DB_PsAS","T");
define("DB","ipaddress/orcl.profits");
$conn = oci_connect(DB_USR,DB_PAS,DB);
if (!$conn)
{
$e = oci_error();
$result["message"] = $e['message'];
echo json_encode($result);
exit(1);
}
$loggedinuser = $_POST['loggedinuser'];
$stmt = "select count(*) as taskgiven from admtask where CLOSE_DT is null and primary='".$loggedinuser."' ";
$stmt1 = "select count(*) as mytask from admtask where CLOSE_DT is null and entusr='".$loggedinuser."' ";
$result=oci_parse($conn,$stmt);
$ex2=oci_execute($result);
while ($row=oci_fetch_assoc($result))
{
$stmta[] = $row;
}
json_encode($stmta);
$result1=oci_parse($conn,$stmt1);
$ex2=oci_execute($result1);
while ($row1=oci_fetch_assoc($result1))
{
$stmtb[] = $row1;
}
json_encode($stmtb);
$final[] = json_decode($stmta,true);
$final[] = json_decode($stmtb,true);
$json_merge = json_encode($final);
echo json_encode($json_merge);
?>
你需要专注于 stmta, stmtb 最后json_merge
不应在包含 JSON 的数组上调用 json_encode()
。将原始数组放在容器数组中,然后对整个事情调用json_encode()
。
$final = array($stmta, $stmtb);
echo json_encode($final);
json_encode返回 JSON 的字符串。您需要在前两个编码期间将其分配给变量。
while ($row=oci_fetch_assoc($result))
{
$stmta[] = $row;
}
$stmta = json_encode($stmta);
$result1=oci_parse($conn,$stmt1);
$ex2=oci_execute($result1);
while ($row1=oci_fetch_assoc($result1))
{
$stmtb[] = $row1;
}
$stmtb = json_encode($stmtb);