[英]Multiple SELECT variables are not displaying
在SELECT内显示所有选定数据条目时出现问题。 现在,唯一显示的是配方直接数据。 每个表数据应在一行中列出名称,名称,直接名称,身份验证名称和身份验证电子邮件。
<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-状态,表标记应位于循环之外
一切看起来正确,直到你foreach
为止。
<blockquote>
<table class="table table-striped">
<?php foreach ($recipes as $id => $recipe): ?>
<tr>
<td><?php $recipe_html = $recipe['recipe_name']; ?></td>
<td><?php $recipe_html = $recipe['recipe_ingred']; ?></td>
<td><?php $recipe_html = $recipe['recipe_direct']; ?></td>
<td><?php $recipe['author_name']; ?></td>
<td><?php $recipe['author_email']; ?></td>
</tr>
<p> //seems you were missing opening <p> tag//
<?php htmlout($recipe_html); ?> |
<a href="updaterecipe.php?id=<?=$id?>">edit</a> | //can use shorthand here//
<a href="deleterecipe.php?id=<?=$id?>">delete</a> //can use shorthand here//
</p>
<?php endforeach; ?>
</table>
</blockquote>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.