$result = $conn->query("SELECT * FROM mails");
while($row = $result->fetch_assoc()){
$mymail= $row['mail']. ",";
echo $mymail;
}
我在每行逗号(,)后都有,但我不想在最后一行之后(,)。我怎么能这样做?
答案 0 :(得分:0)
查看join功能:
$mails = array();
$result = $conn->query("SELECT * FROM mails");
while($row = $result->fetch_assoc())
{
$mails[] = $row['mail']; // Store E-Mail adresses in an array
}
$commaSeparatedMails = join(',', $mails); // Connect all array parts using a comma
echo $commaSeparatedMails;
答案 1 :(得分:0)
rtrim(yourstring,","),此函数将删除右逗号。