gpt4 book ai didi

php - PHP 中的 EOT 仅显示一行

转载 作者:行者123 更新时间:2023-11-29 19:47:03 24 4
gpt4 key购买 nike

我有一个名为 products 的表当我尝试显示表中的所有产品时,它只显示一项。我的代码有什么问题吗?

当我尝试 echo $obj->product_id在 while 循环内,它工作正常并返回所有行。

这是我的代码:

<!-- 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 -->

这是我的数据架构 enter image description here

无论如何,当我尝试向 .=<<<EOT 添加连接符号时它返回所有行,但也创建一个新表。

最佳答案

试试这个刚刚向 $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
....
....

关于php - PHP 中的 EOT 仅显示一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40909453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com