我有一个名为products
的表格,当我尝试在表格中显示所有产品时,它只显示一个条目。我的代码出了什么问题?
当我在while循环中尝试echo $obj->product_id
时,它工作正常并返回所有行。
这是我的代码:
<!-- Products List Start -->
<?php
$results = $connection->query("SELECT product_id, product_name, product_desc, product_buyp, product_quantity FROM products ORDER BY product_id ASC");
if($results){
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
$products_item = <<<EOT
<form method="post" action="cartUpdate.php">
<table class="table table-condensed table-hover">
<thead>
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Description</th>
<th>Instock</th>
<th>Buy Price</th>
<th>Qty</th>
</tr>
</thead>
<tbody>
<tr>
<td>{$obj->product_id}</td>
<td>{$obj->product_name}</td>
<td>{$obj->product_desc}</td>
<td>{$obj->product_quantity}</td>
<td>{$obj->product_buyp}</td>
<td><input type="number" size="2" maxlength="6" name="product_qty"></td>
</tr>
</tbody>
</table>
<input type="hidden" name="product_id" value="{$obj->product_id}" />
<input type="hidden" name="type" value="add" />
<input type="hidden" name="return_url" value="{$current_url}" />
<button type="submit" class="add_to_cart">Add</button>
</form>
EOT;
}
echo $products_item;
}
?>
<!-- Products List End -->
无论如何,当我尝试将一个concat符号添加到.=<<<EOT
时,它会返回所有行,但它也会创建一个新表。
答案 0 :(得分:0)
尝试这个 刚刚将连接添加到$ products_item
<!-- Products List Start -->
<?php
$results = $connection->query("SELECT product_id, product_name, product_desc, product_buyp, product_quantity FROM products ORDER BY product_id ASC");
if($results){
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
$products_item.= <<<EOT //added conc
....
....