douzao5487 2016-11-22 18:17
浏览 28
已采纳

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

I am running into a problem with an imploding list. The data is correct, but I cannot figure out how to put it into a format to where each result (piece of data) is wrapped into the div I am attempting to surround it with:

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

I am wanting it to appear like this:

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

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

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

All this is doing now is putting all of the imploded data into one div like, <div class="pending-friend-list-row">123</div>

Any ideas?

Full code:

$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;
}
  • 写回答

3条回答 默认 最新

  • duanjing1023 2016-11-22 18:20
    关注

    You want your glue to end one div and start the next like this:

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

    More on how to use glue with implode

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)