有谁知道如何通过PHP数组创建多个卡?
例如,我有5个friend
和5个description
对应每个朋友(从mysqli表中)保存在$friendList
中。
因此,我想为每一行创建并显示一张卡片,其中以朋友为标题,并将其描述作为卡片的内容。
这将是循环
while ($row = mysqli_fetch_array($friendList, MYSQLI_ASSOC)){
// $row['friend'];
// $row['description'];
}
但是,我不知道如何使用获得的变量来创建卡片:
最佳答案
假设您已经定义了$friendList
变量并且它是一个mysqli_result
对象,则可以按照以下方法进行操作:
<?php while($row = mysqli_fetch_array($friendList, MYSQLI_ASSOC)): ?>
<div class="w3-card-4 test">
<img src="img_avatar3.png" alt="Avatar">
<div class="w3-container">
<h4><b><?php echo $row["friend"] ?></b></h4>
<p><?php echo $row["description"] ?></p>
</div>
</div>
<?php endwhile; ?>
随意问任何问题 :-)
关于php - 从PHP数组创建CSS卡?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44030985/