如何在PHP中输出MySQL表
我正在测试这段代码
$query = "SELECT * from `items` where category_id=?";
$stmt = $mysqli->query($query);
$stmt->bind_param("s", $category_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $stmt->fetch_assoc()) {
printf ("%s (%s)\n", $row['name'], $row['code']);
}
有没有更简单的方法将整个表输出到 HTML 标记?
I'm testing this code
$query = "SELECT * from `items` where category_id=?";
$stmt = $mysqli->query($query);
$stmt->bind_param("s", $category_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $stmt->fetch_assoc()) {
printf ("%s (%s)\n", $row['name'], $row['code']);
}
Is there any easier way to output whole table to HTML markup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然。
学习使用模板。
只需将准备好的语句与输出分开即可。
为此,首先将数据收集到 array:
中,然后使用您喜欢的任何 HTML 标记开始输出(最好通过包含单独的模板文件:
Sure.
Learn to use templates.
Just separate your prepared statements from output.
To do so, at first collect your data into array:
and then start output with whatever HTML markup you like (preferably by means of including a separate template file:
以下代码片段可以满足您的要求..但我不确定这是否是更简单的方法..希望这会有所帮助。
对于 php,
对于 js,
The following code snippet can match your requirements..but i'm not sure whether this is easier way or not..Hope this will help.
For the php,
For the js,