PHP - 将关联数组输出到 HTML <divs with labels/headings

标签 php html mysql

我有一个 PHP 函数,它从本地主机 MySQL 表中返回一行,如下所示:

<?php
//include database connection process
require_once("includes/conn.inc.php");
//prepare statement
$stmt = $conn->prepare("Select * FROM races WHERE raceID = ?");
$id = 1;
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
?>

我想对这个数组做的是在它们自己的 HTML 中输出来自各个字段的数据 <div><p>带有一个标题,表明它们在单独的 div 中的含义。我目前使用 print_row一种输出所有内容的方法。我想要的所有数据都在那里,但我希望将其分成名称/值段落或 div。

//what I currently have
<?php
    print_r($row);
?>

有办法吗?

提前致谢

标记

最佳答案

我不是很理解这个问题,但我想我明白你需要什么。

使用 while 遍历每一行。

while($row = $resultDesc->fetch_assoc())
{
    echo '<p><strong>Description:</strong></p> ';
    echo '<p>'. $row['description'] . '</p>';
}

这不是确切的解决方案,但至少向您展示了路径。

关于PHP - 将关联数组输出到 HTML <divs with labels/headings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35229869/

相关文章:

php - PHP将所有行作为数组获取

php - "Meta-objects"?

html - 嵌套的 CSS id 可以在 firefox 中使用,但不能在 IE8 中使用?

php - 更新外键

html - 似乎 `border-box` 不适用于 `a` 标签的内联 block

javascript - 单击时更改按钮图像并在 iframe 中显示结果,单击下一个按钮时,将原始按钮返回到第一个按钮

java - 我需要有关使用 JDBC 的 INSERT 语句的帮助

php - utf8_encode 函数用途

javascript - Jquery调用PHP进行处理?

php - Codeigniter 将新项目添加到当前 session 用户数据数组