pg-admin“ WHERE”子句无法正常工作

时间:2019-12-04 14:07:40

标签: php pgadmin

我想显示基于前一周的数据。  我对pg-admin的查询是

"SELECT * FROM event  WHERE datetime BETWEEN NOW()-INTERVAL '6 DAYS' AND NOW()"

它在pg-admin编辑器中工作正常,并向我显示正确的数据,但是当我对php代码实施此查询时,它没有显示所需的结果。  我的php代码是

$queryStr ="SELECT * FROM event  WHERE datetime BETWEEN NOW()-INTERVAL '6 DAYS' AND NOW()";
    $result = pg_query($conn,$queryStr);
    if (!$result) {
        echo "An error occurred in query.\n";
        exit;
    }
    $result = pg_fetch_assoc($result);      
    return $result; 

它只显示一行解决方案?

1 个答案:

答案 0 :(得分:0)

使用类似下面的内容:

while ($row = pg_fetch_assoc($result)) 
{ 
echo $row['id']; 
echo $row['author']; 
echo $row['email']; 
}