使用PHP从HTML网页查询Postgres DB表数据 [英] Query the Postgres DB table data from HTML webpage using PHP
问题描述
我有一个包含6列的postgres数据库表
I have a postgres database table with 6 columns
report_dt | configured_capacity_tb | present_capacity_tb | dfs_remaining_tb | dfs_used_tb | env
当我从下拉菜单中选择一个选项时,第5列应在HTML网页中显示为下拉菜单按下并提交,我应该以网页上的表格形式从postgres db表中获取数据
The 5th column should appear as a drop down in HTML webpage when i select an option from that drop down and hit submit I should get the data(from postgres db table) in a form of table on webpage
以下是我的破损代码,
echo 'Connection attempt succeeded.';
} else {
echo 'Connection attempt failed.';
}
$sql =<<<EOF
select * from cluster_report_tab;
EOF;
$ret = pg_query($db, $sql);
if(!$ret){
echo pg_last_error($db);
exit;
}
<<<I AM STUCK AT THIS PIECE>>>>
<html>
<head><title>Cluster Report</title>
</head>
<body>
<p></p>
<table width="600" cellpadding= "10" cellspacing="1" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Hadoop Cluster Report</h3>
****DROP DOWN SHOULD COME HERE*****
<input type="Submit" name="submit" value="Submit">
</td></tr></table></form>
</body>
</html>
当我从下拉菜单中选择选项并点击网页上的提交按钮时,它应该向我显示查询结果#从cluster_report_tab中选择*,其中env ='DHEP';
When I select the option from that drop down and hit submit button on webpage It should display me the query result# select * from cluster_report_tab where env='DHEP'; on the webpage.
谢谢
推荐答案
没关系...以下代码解决了我的问题...感谢您的所有建议
Never mind...The following piece of code solved my problem...Thanks for all your suggestions
$result=pg_query("select * from cluster_report_tab where env = '$_POST[Envi]'");
while ($row = pg_fetch_row($result)) {
echo "<tr>";
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<td>$row[2]</td>";
echo "<td>$row[3]</td>";
echo "<td>$row[4]</td>";
echo "<td>$row[5]</td>";
echo "</tr>";
}
pg_close($db);
?>
这篇关于使用PHP从HTML网页查询Postgres DB表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!