gpt4 book ai didi

php - 不显示多个 SELECT 变量

转载 作者:行者123 更新时间:2023-11-29 12:31:52 25 4
gpt4 key购买 nike

在 SELECT 中显示所有选定的数据条目时出现问题。现在唯一显示的是recipe_direct 数据。每个表数据应在一行中列出名称、ingred、direct、auth name 和 auth email。

  <div class="starter-template">
<h1>Recipes</h1>
</div>
<?php
try
{
$sql = 'SELECT recipe_id, recipe_name, recipe_ingred, recipe_direct, author_name, author_email FROM recipes';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching recipes: ' . $e->getMessage();
}
while ($row = $result->fetch())
{
$recipes[$row['recipe_id']] = $row;
}
?>

<p><a href="addrecipe.php">Add a Recipe</a></p>
<?php foreach ($recipes as $id => $recipe): ?>
<blockquote>
<table class="table table-striped">
<tr>
<td><?php echo $recipe['recipe_name']; ?></td>
<td><?php echo $recipe['recipe_ingred']; ?></td>
<td><?php echo $recipe['recipe_direct']; ?></td>
<td><?php echo $recipe['author_name']; ?></td>
<td><?php echo $recipe['author_email']; ?></td>
</tr>
<?php htmlout($recipe_html); ?> |
<a href="updaterecipe.php?id=<?php echo $id; ?>">edit</a> |
<a href="deleterecipe.php?id=<?php echo $id; ?>">delete</a>
</table>
</blockquote>
<?php endforeach; ?>

最佳答案

每次赋值时都会覆盖 $recipe_html

为什么不直接回显表格行:

  <table>
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?= $recipe['recipe_name']; ?></td>
<td><?= $recipe['recipe_ingred']; ?></td>
<td><?= $recipe['recipe_direct']; ?></td>
<td><?= $recipe['author_name']; ?></td>
<td><?= $recipe['author_email']; ?></td>
</tr>
<?php endforeach; ?>
</table>

EdIt 正如 @Fred -ii- 所说,表格标签应该位于循环之外

关于php - 不显示多个 SELECT 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27370624/

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