我有一些PostgreSQL查询,其输出如下所示。现在我想显示该输出查询PHP如何做到这一点? 我的PostgreSQL的查询如下:如何使用PostgreSQL查询在PHP中创建表?
$query = 'select
round(
100.00 *
(sum(case when "WELLTYPE"= 'DT' and ("CONC_ARSC" between 0 and 10) then 1 else 0 end))/(sum(case when "WELLTYPE"= 'DT' then 1 else 0 end)),1) "0-10",
round(
100.00 *
(sum(case when "WELLTYPE"= 'DT' and ("CONC_ARSC" between 11 and 50) then 1 else 0 end))/(sum(case when "WELLTYPE"= 'DT' then 1 else 0 end)),1) "11-50",
round(
100.00 *
(sum(case when "WELLTYPE"= 'DT' and ("CONC_ARSC" >50) then 1 else 0 end))/(sum(case when "WELLTYPE"= 'DT' then 1 else 0 end)),1) ">50",
round(
100.00 *
(sum(case when "WELLTYPE"= 'DT' and ("CONC_ARSC" between 0 and 10) then 1 else 0 end))/(sum(case when ("WELLTYPE"= 'DT' or "WELLTYPE"= 'DW' or "WELLTYPE"= 'FT' or "WELLTYPE"= 'ST') and ("CONC_ARSC" between 0 and 10)then 1 else 0 end)),1) "Total"
from public."Arsenic_Test"';
上述PostgreSQL的查询的输出是这样的:
____________________________________________
|0_to_10| 11_to_50 | greater_than_50 | Total|
--------+----------+-----------------+------|
| 100 | 0.0 | 0.0 | 0.4 |
----------------------------------------------
我是在PHP非常beginer所以我不知道如何下手。我有安装数据库连接和它的工作正常。我已经(使用PHP)
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$db_connection = pg_connect("host=localhost port=5433 dbname=BankeDB user=postgres password=admin");
echo $db_connection;
$query = 'select.... (above query) ';
$result = pg_query($db_connection, $query, $POST);
$result = pg_query($db_connection, $query);
$DT = array('0-10','11-50','>50',total);
$result = pg_query($db_connection, $query);
while ($DT = pg_fetch_row($result)) {
echo "<tr>";
echo "<td>$DT[0]</td>";
echo "<td>$DT[1]</td>";
echo "<td>$DT[2]</td>";
echo "<td>$DT[3]</td>";
echo "<td>$row[4]</td>";
echo "</tr>";
}
echo $result;
pg_close($db);
请发布您尝试过的以及您遇到的任何错误。此外,你想要的输出的例子会很好。 – ChristianF
我很开心在PHP中,所以我不知道如何开始。我有安装数据库连接和它的工作正常。我创建了一个数组来创建表格(使用php) – Ram
@ChristianF我已经添加了一些我迄今为止所做的信息。你能帮我解决吗? – Ram