[英]How to show add one row of a mysql Table?
Hi i want to show all the data of one row in a table.But i can only show 1 column of the table.嗨,我想显示表格中一行的所有数据。但我只能显示表格的 1 列。
function getAllRecipes(): array {
global $connection;
$query = "SELECT * FROM recipe";
$stmt = $connection->prepare($query);
$stmt->execute();
return $stmt->fetchAll();
}
$recipe = getAllRecipes();
<?php foreach ($recipe as $recip) : ?>
<table>
<tr>
<td><?= **$recip["id"];** ?></td> <----here
</tr>
</table>
and i want all of the line:我想要所有的行:
Do you know how to do it?你知道怎么做吗?
Thanks for your help谢谢你的帮助
Based on "i just want by one line show all the contain of th row" in your "answer".基于“我只想通过一行显示所有包含的行”在您的“答案”中。
$arr_values = array_values($recipe);
$html = '<table><tr><th>' . implode('</th><th>', $arr_values) . '</tr></table>';
echo $html;
If you simply only want the name of the keys(columns):如果您只想要键(列)的名称:
$arr_keys = array_keys($recipe);
$html = '<table><tr><th>' . implode('</th><th>', $arr_keys) . '</tr></table>';
echo $html;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.