我有一些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