从postgres到php再到html(使用ajax)获取数据


getting data from postgres to php to html (with ajax)

我正在使用ajax调用一个php脚本,该脚本从我的postgres DB中获取数据。在php中,我的代码是:

$sql = "select * from processWebRequest($1)";
$res = pg_prepare($dbconn, "interaction_insert_query", $sql);
$res = pg_execute($dbconn, "interaction_insert_query", array($req));
$myarray = array();
while ($row = pg_fetch_assoc( $res )/*pg_fetch_row($contests)*/) {
  $myarray[] = $row;
}
header('Content-Type: application/json');
echo json_encode($myarray);// 

问题是在ajax 中

$.ajax({
    url: "../php/recordInteraction.php",
    type: 'GET',
    data : pObject,
    dataType: 'json',
    success: function(response,textStatus,jqXHR){

响应变量似乎包含越来越多的数据。我知道每个查询最多返回两行,但当我在调试器中加载文件时,响应变量是一个包含25行的数组。

好像我需要冲什么东西,我只是不知道是什么。

有人能帮忙吗?谢谢

直接调用端点并调试数据库查询以查看结果。看来你要倒退25排了。

while ($row = pg_fetch_assoc( $res )/*pg_fetch_row($contests)*/) {
var_dump( $row );
  $myarray[] = $row;
}

while ($row = pg_fetch_assoc( $res )/*pg_fetch_row($contests)*/) {
    $myarray[] = $row;
}
var_dump( $myarray );
die;