如何将下面$row["comment"]
中显示的所有评论合并到一个名为$commentstring
的巨型字符串变量中?
$sqlStr = "SELECT comment.comment, comment.datecommented, comment.commentid, comment.points, login.username
FROM comment
LEFT JOIN login ON comment.loginid=login.loginid
WHERE submissionid=$submissionid
ORDER BY comment.points DESC
LIMIT 100";
$tzFrom1 = new DateTimeZone('America/New_York');
$tzTo1 = new DateTimeZone('America/Phoenix');
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"commentecho\">";
$count = 1;
while ($row = mysql_fetch_array($result)) {
$dt1 = new DateTime($row["datecommented"], $tzFrom1);
$dt1->setTimezone($tzTo1);
echo '<tr>';
echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-top:3px solid #DE2A00;" class="commentname2user"><a href="http://www.domain.com/directory/'.$row["username"].'">'.$row["username"].'</a></td>';
echo '<td style="border-bottom:3px solid #DE2A00; border-top:3px solid #DE2A00; border-right:3px solid #DE2A00;" rowspan="4" class="commentname1" id="comment-' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00;" class="commentname2">'.$dt1->format('F j, Y').'</td>';
echo '</tr>';
echo '<tr style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-bottom:0px solid #DE2A00;">';
echo '<td style="border-left:3px solid #DE2A00;" class="commentname2"></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="border-left:3px solid #DE2A00; background-color: #DE2A00; border-bottom:3px solid #DE2A00;" class="commentname2user"><span class=""><a href="http://www.domain.com/directory/comments/commentpoints.php?submission='.urlencode($submission).'&submissionid='.$submissionid.'&link='.$link.'&submittor='.$submittor.'&submissiondate='.$submissiondate.'&dispurl='.$dispurl.'&subcheck='.$subcheck.'&points='.$points.'&city='.$city.'&commentpoints='.number_format($row["points"]).'&commenter='.$row["username"].'">'.number_format($row["points"]).'</a><span></td>';
echo '</tr>';
echo '<tr>';
echo '<td style="border-bottom:0px solid #DE2A00; border-right:0px solid #DE2A00;" class="commentname2a"></td>';
echo '</tr>';
}
echo "</table>";
答案 0 :(得分:3)
在while-loop
之前声明$commentstring = "";
在while循环中:
$commentstring .= $row["comment"];
答案 1 :(得分:1)
如果你把它放在你的while循环之前:
$commentstring = '';
然后在while循环内添加到它上面:
$commentstring .= $row['comment'];
或者与新行一起:
$commentstring .= $row['comment'] . '<br />';