在sql列中获取行

g0czyy6m  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(178)

你好,stackoverflow社区。我正在尝试获取sql表中在页上创建新“object”的列。数据在同一列中,我需要按行分别获取它。
注:\n=断线品牌
\zn=插入“删除按钮”的品牌
我的代码:

<?php 
            $conn = new mysqli("localhost", "root", "blahblah", "blahbla_database");
            $userglobal = $w['user']['username']; // this get username of logged user
            $sql = "SELECT emails FROM users WHERE (`username` = '{$userglobal}')";
            $result = $conn->query($sql);
                     if($result->num_rows > 0) {
                           while($row = $result->fetch_assoc()) {
                              if ($row["emails"] !== NULL) {
                              echo "<div class='list-group'>";
                              echo "<a href='./mail' target='_blank' class='list-group-item list-group-item-action'>";
                              $mail_showed = nl2br($row["emails"]);
                              $mail_showed = str_replace('\n', "<br />", $mail_showed);
                              $mail_showed = str_replace('\zn', "", $mail_showed);

                              echo $mail_showed;
                              echo "<span class='badge badge-primary badge-pill'>".CountNewMails($mail_var)."</span></a>"; // Get new mails in number then show it
                              echo "</div>";
                            } else { echo "<h5 class='text-center'>".$w['user']['username']." You dont have yet mail</h5>";}
                           }
                       }
              ?>

结果是:

<div class='list-group'>
<a href='./mail' target='_blank' class='list-group-item list-group-item-action'>usermail@domain.com
<span class='badge badge-primary badge-pill'>14</span></a>
</div>

问题:列中的邮件地址超过1个时,邮件显示为:

<div class='list-group'>
    <a href='./mail' target='_blank' class='list-group-item list-group-item-action'>usermail@domain.com<br>2mail@domain.com
    <span class='badge badge-primary badge-pill'>14</span></a>
</div>

我需要的是:

<div class='list-group'>
        <a href='./mail' target='_blank' class='list-group-item list-group-item-action'>usermail@domain.com
        <span class='badge badge-primary badge-pill'>14</span></a>
       <a href='./mail' target='_blank' class='list-group-item list-group--item-action'>2mail@domain.com
        <span class='badge badge-primary badge-pill'>99</span></a>

    </div>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题