<textarea style="resize: none;">
<?php
while ($row = mysql_fetch_array($result)) {
echo $row[1] . "\n";
}
?>
</textarea>
我想阻止最后一个值出现换行 - 我该怎么做呢?我不希望底部有空白区域。
答案 0 :(得分:5)
<textarea style="resize: none;">
<?php
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row[1];
}
echo implode($rows, "\n");
?>
</textarea>
答案 1 :(得分:0)
我通常做这样的事情:
<textarea style="resize: none;">
<?php
while ($row = mysql_fetch_array($result)) {
if($stuff==''){
$stuff=$row[1];
}else{
$stuff.= "\n" . $row[1];
}
}
print $stuff;
?>
</textarea>
答案 2 :(得分:0)
<?php
$results = array();
while ($row = mysql_fetch_array($result))
$results[] = $row[1];
echo implode("\n", $results);
?>
或
<?php
$first = true;
while ($row = mysql_fetch_array($result)) {
if (!$first)
echo "\n";
echo $row[1];
$first = false;
}
?>
答案 3 :(得分:0)
将行保存在变量中,然后从字符串中删除最后一个字符。
<?php
$content = '';
while ($row = mysql_fetch_array($result)) {
$content .= $row[1] . "\n";
}
echo substr($content, 0, strlen($content) - 1);
?>
答案 4 :(得分:0)
这应该有效:
<?php
$string = '';
while ($row = mysql_fetch_array($result)) {
$string .= $row[1] . "\n";
}
?>
<textarea style="resize: none;">
<?php echo trim($string,"\n"); ?>
</textarea>
答案 5 :(得分:0)
一种方法是这样做:
<textarea style="resize: none;">
<?php
$prefix= '';
while ($row = mysql_fetch_array($result)) {
echo $prefix . $row[1];
if($prefix == ''){
$prefix = "\n";
}
?>
</textarea>