雑貨りんくパソコン雑記 > pg_execでテーブル表

pg_execでデータベースのテーブル表をつくるサンプル


<?php

$result = pg_exec($con,"select * from hoge");
$rows=pg_numrows($result);
$columns=pg_numfields($result);

echo "<table border=1>";
echo "<tr>";
for($i=0;$i<$columns;$i++){
$str=pg_fieldname($result,$i);
print("<th>$str</th>");
}
echo "</tr><tr>";

for($i=0;$i<$rows;$i++){
$row = pg_fetch_row($result,$i);

for($j=0;$j<$rows;$j++){

for($i=0;$i<$columns;$i++){
$str = pg_result($result, $j, $i);
echo "<td>$str</td>";
}
echo "</tr>";
}
echo "</tr>";
echo "</table>";

?>