Hello Stackoverflow社区。 我尝试在SQL表中提取在页面上创建新“对象”的列。 数据在同一列中,我需要按行分别提取。
注意:\ 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>
问题: 当in栏中的邮件地址超过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>