注意第二行到最后一行的连接' \ n'。它似乎被添加到字符串的一部分而不是像我想要的那样充当换行符。
关于我做错了什么的想法?
我试图在在线编码练习环境中展示这一点。没有涉及HTML。
<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'password';
$rec_limit = 10;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('test_db');
/* Get total number of records */
$sql = "SELECT * FROM trail101 WHERE activities IN(\'Murals\',\'Concert\',\'Theater\',\'Museums\') ORDER BY id";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) ) {
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else {
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT * ".
"FROM trail101 ".
"WHERE activities IN(\'Murals\',\'Concert\',\'Theater\',\'Museums\') ORDER BY id ".
"LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "ID :{$row['id']} <br> ".
"ACTIVITY NAME : {$row['activity_name']} <br> ".
"--------------------------------<br>";
}
if( $page > 0 ) {
$last = $page - 2;
echo "<a href = \"$_PHP_SELF?page = $last\">Last 10 Records</a> |";
echo "<a href = \"$_PHP_SELF?page = $page\">Next 10 Records</a>";
}else if( $page == 0 ) {
echo "<a href = \"$_PHP_SELF?page = $page\">Next 10 Records</a>";
}else if( $left_rec < $rec_limit ) {
$last = $page - 2;
echo "<a href = \"$_PHP_SELF?page = $last\">Last 10 Records</a>";
}
mysql_close($conn);
?>
</body>
</html>
答案 0 :(得分:1)
\n
可以帮助您在输入框的值中添加换行符,但不会在innerHTML
或textContent
中添加换行符。
使用</br>
代替
outputString += list[i] + '</br>';