PHP购物车内容打印输出
我有一个简单的商店显示PostgreSQL数据库中的数据:PHP购物车内容打印输出,php,html,sql,postgresql,xhtml,Php,Html,Sql,Postgresql,Xhtml,我有一个简单的商店显示PostgreSQL数据库中的数据: $database = pg_connect("host= port= "); $query = 'SELECT * FROM table1 '; $query .= ' ORDER BY Price'; $result = pg_query($database, $query); echo '<form name="basket" action="basket.php" method="post">' . '<t
$database = pg_connect("host= port= ");
$query = 'SELECT * FROM table1 ';
$query .= ' ORDER BY Price';
$result = pg_query($database, $query);
echo '<form name="basket" action="basket.php" method="post">' . '<table border="1" class="center">';
echo "<tr></tr>";
while ($a = pg_fetch_row($result)) {
echo "<tr>";
echo "<td><input type='checkbox' name='games[]' value='.$id.' ></td>";
for ($j = 0; $j < pg_num_fields($result); $j++) {
echo "<td>" . $a[$j] . "</td>";
}
echo "</tr>\n";
}
echo '</table>';
?>
<input type="submit" name="Add To Basket" value="Add To Basket" />
</form>
但这会产生以下结果:
array(4) { [0]=> string(2) ".." [1]=> string(2) ".." [2]=> string(2) ".." [3]=> string(2) ".." } Array ( [0] => .. [1] => .. [2] => .. [3] => .. )
有人能帮我吗谢谢你在字段值中添加了
,例如value=“.7.”
echo”“;
^---^--
您也没有在任何地方定义
$id
,因此您正在输出一个未定义的变量,该变量将生成一个空白点。复选框中没有$id
值,添加为$id=$a[0]代码>
while ($a = pg_fetch_row($result)) {
$id = $a[0];
echo "<tr>";
echo "<td><input type='checkbox' name='games[]' value='$id' ></td>";
for ($j = 0; $j < pg_num_fields($result); $j++) {
echo "<td>" . $a[$j] . "</td>";
}
echo "</tr>\n";
}
while($a=pg\u fetch\u row($result)){
$id=$a[0];
回声“;
回声“;
对于($j=0;$j
echo "<td><input type='checkbox' name='games[]' value='.$id.' ></td>";
^---^--
while ($a = pg_fetch_row($result)) {
$id = $a[0];
echo "<tr>";
echo "<td><input type='checkbox' name='games[]' value='$id' ></td>";
for ($j = 0; $j < pg_num_fields($result); $j++) {
echo "<td>" . $a[$j] . "</td>";
}
echo "</tr>\n";
}