在AngularJS中的$http.post查询后返回2个表

Returning 2 tables after a $http.post query in AngularJS

本文关键字:查询 返回 2个表 post http AngularJS 中的      更新时间:2023-12-27

我觉得这是一个非常简单的问题,但我不确定语法。我在javascript文件中执行$http.post查询

$http.post('server.php', {"data" : cleTexte, "serverFlag" : 2})
            .success(function(data, status) 
            {
                console.log(data);
                grantTable = data; 
            }

php文件在SQL查询后返回一个表:

$result = $conn->query("SELECT grantAmount FROM granttoassociation WHERE HEX(grantReceiver) = '$key' ");
while($rs = $result->fetch()) {
        if ($outp != "") {
            array_push($outp,$rs["grantAmount"]);
        }
}
$outp =json_encode($outp);
echo($outp);

而且,正如您所看到的,结果会影响到javascript文件中的grantTable。它很好用,不过,我想要两张桌子。第二个表将在php文件中的第二个SQL查询之后获得。javascript文件中的最终结果应该是:

$http.post('server.php', {"data" : cleTexte, "serverFlag" : 2})
            .success(function(data, status) 
            {
                console.log(data);
                grantTable = data...
                grantYear = data...
            }

我该怎么做?

第二个SQL查询类似于:

"SELECT grantYear FROM granttoassociation WHERE HEX(grantReceiver) = '$key' "

基本思想是运行类似的东西

"SELECT grantYear, grantAmount FROM granttoassociation WHERE HEX(grantReceiver) = 'yourkey' "

不过,请注意SQL注入,并使用PDO传递参数或mysqli_。

在javascript中,您可以将数据和.push的相应列迭代到要在中保存的对象

function(data, status)
{
    console.log(data);
    grantTable = [];
    grantYear = [];
    for (var index in data) {
        grantTable.push(data[index]["grantAmount"]);
        grantYear.push(data[index]["grantYear"]);
    } 
}