php - PHP 函数的 HTML
问题描述
我使用准备好的语句来收集数据。我正在尝试使用 fetch_array 函数以有组织的方式显示该数据。是否可以将 html 表插入到依赖于准备好的语句的 php 函数中?
我读过使用 HEREDOC,但我不知道用什么来代替变量。我也尝试为表格创建另一个文档,但有同样的问题。
这是我正在使用的功能。
function showProfile($user) {
global $connection;
$query = "SELECT * FROM profiles WHERE user='$user'";
$result = $connection->query($query);
/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
printf(
"%s <br> %s\n",
$row["forename"],
$row["surname"]
) . "<br style='clear:left;'><br>";
}
这是我要使用的表
<table width="398" border="0" align="center" cellpadding="0">
<tr>
<td height="26" colspan="2">Your Profile Information </td>
</tr>
<tr>
<td width="82" valign="top"><div align="left">FirstName:</div></td>
<td width="165" valign="top"><?php echo $forename ?></td>
</tr>
<tr>
<td valign="top"><div align="left">LastName:</div></td>
<td valign="top"><?php echo $surname ?></td>
</tr>
</table>
我可以使用该功能显示我的数据,但是,我想以更有条理的方式显示它。
解决方案
而不是 printf(),你可以回显
echo "<table width='398'> <-- check here the quote marks so the string doesnt break
<tr>
<td>".$row['forename']."</td> <- then concat all the variables you want like this
</tr>
</table>";
推荐阅读
- c# - 如何为 FakeItEasy 构建一个 HttpResponseHeaders
- c# - 在 C# 中使用 And 和 Or 逻辑查询过滤器
- algorithm - 基于比较的排序是WC min time nlogn,那么最好/平均情况呢
- python - Scrapy构建JSON字典:“TypeError:只能将str(不是“set”)连接到str”
- angular - 使用 NGRX 的 RXJS 链订阅反模式
- dataframe - dataframe-go:如何使用 < > 运算符进行过滤?
- math - 了解角速度及其应用
- c# - 水平滚动文本未重置为起始位置
- c# - UWP TreeView - 更新绑定后的数据使可扩展图标消失
- ios - 添加带有图像的按钮会扭曲堆栈视图