gpt4 book ai didi

php - 将每个单独的数组数据 block 包装在自己的 div 中

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:48 26 4
gpt4 key购买 nike

我遇到了内爆列表的问题。数据是正确的,但我无法弄清楚如何将其放入一种格式,以便将每个结果(数据)包装到我试图用它包围的 div 中:

$pending_friend_list = '<div class="pending-friend-list-row">'. implode($friends_pending_arr) . '</div>';

我希望它看起来像这样:

<div class="pending-friend-list-row">1</div>

<div class="pending-friend-list-row">2</div>

<div class="pending-friend-list-row">3</div>

现在所做的就是将所有内爆数据放入一个 div 中,例如 <div class="pending-friend-list-row">123</div>

有什么想法吗?

完整代码:

$friends_pending_arr = array();
$friends_pending_sql = "
SELECT *
FROM friends
WHERE friend_two = ?
AND status = ?
";
$pending_friend_count_stmt = $con->prepare($friends_pending_sql);
$pending_friend_count_stmt->execute(array($user_id, $status_one));
$pending_friend_rows = $pending_friend_count_stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<div id="pending-request_count">Total Pending Friends -' . $total_pending_count . '</div>';
foreach ($pending_friend_rows as $pending_friend_row) {
$pending_friend_1 = $pending_friend_row['friend_one'];
$pending_friend_2 = $pending_friend_row['friend_two'];
$pending_friend_status = $pending_friend_row['status'];
$pending_friend_status_date = $pending_friend_row['date'];
$total_pending_friends = $pending_friend_1 . "<br>" . $pending_friend_2;

if ($pending_friend_2 == $user_id) {
$friends_pending_arr[] = $pending_friend_1;
}
}
//echo implode("<br>",$friends_pending_arr);
//$pending_friend_list = implode("<br>",$friends_pending_arr);
$pending_friend_list = '<div class="pending-friend-list-row">'. implode($friends_pending_arr) . '</div>';
echo $friend_status_button . "<br>";
echo $profile_viewer_message;
?>
<div id="main">
<div id="pending-friend-list-container">
<div id="pending-friend-list-summary">
<?php //echo '<div class="pending-friend-list-row">'. $pending_friend_list . '</div>';
echo $pending_friend_list;
?>
</div>

CSS

.pending-friend-list-row {
height: 50px;
width: 100%;
border: 1px solid green;
background: gray;
}

最佳答案

你希望你的胶水像这样结束一个 div 并开始下一个:

$pending_friend_list = '<div class="pending-friend-list-row">'. implode('</div><div class="pending-friend-list-row">', $friends_pending_arr) . '</div>';

更多关于如何使用胶水 implode

关于php - 将每个单独的数组数据 block 包装在自己的 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40748914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com