我正在开发一个通知系统,我想使用我构建的一种平台来查看配置文件,这些配置文件的 ID 在数据库“友谊”中找到(跟踪发件人、收件人和日期)交友请求)
我一直在尝试找到一种方法来为每一行包含这个配置文件模块(它使用 $_GET 变量来获取用户信息),我需要一种方法来为每一行设置一个变量,然后立即包含该模块使用 ID,但是当我尝试这个时,只出现一个而不是我的 4 个请求。
while ($row = mysqli_fetch_assoc($result)) {
echo "<div class='item friend'>";
$_GET['user'] = $row['sender_id'];
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/profile/module.php";
include_once($path);
echo "</div>";
}
我知道像这样设置变量是错误的,但我不知道该如何去做。
更新:应用 Gautum Rai 的代码后,显示了正确的 div,但它们看起来是空的。
这是我使用原始代码生成的 HTML(与一个人的信息相呼应)。
<div class="item friend">
<div class="profile">
<img class="pic" title="Taswell: Omikron Player" style="background-image: url("/img/badges/omikron.png") !important;" src="/uploads/profile19.jpg?" 2147213591="">
<p class="username">MyNameIsKnuckles<img class="medal" src="/img/medals/dragonfly.png" title="Queen Of The Hive"></p><br>
<p class="bio playing">nothin. just waiting for the next omikron build.</p>
</div>
注意:我已经问过类似的问题,但我收到的评论告诉我加入变量或不使用 while 循环来获取 assoc。请提供相关答案,我将不胜感激。
最佳答案
您正在使用 include_once
,它显式包含文件 一次,并且您的文件名始终相同。尝试仅使用 include
。
关于php - 将每一行用作包含的获取变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46205238/