我需要在表格中显示一些结果,但查询数据显示在表格中。这是代码:
$db = new mysqli('localhost','root','123','news');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT Id FROM news
SQL;
$result=mysqli_query($db,$sql);
print "<table><tr><td>№</td></tr>";
while($row = mysqli_fetch_row($result)){
print '<tr><td>'+$row[0]+'</td></tr>';
}
print "</table>";
结果如下:
1234
№
它应该是这样的:
№
1
2
3
4
答案 0 :(得分:1)
替换&#34; +&#34;用&#34;。&#34; &#34; +&#34;用于添加值,&#34;。&#34;用于连接字符串
$db = new mysqli('localhost','root','123','news');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT Id FROM news
SQL;
$result=mysqli_query($db,$sql);
print "<table><tr><td>№</td></tr>";
while($row = mysqli_fetch_row($result)){
print '<tr><td>' . $row[0] . '</td></tr>';
}
print "</table>";
或使用以下
print "<tr><td>$row[0]</td></tr>";
答案 1 :(得分:1)
使用。而不是+并使用echo而不是print
答案 2 :(得分:0)
print '<tr><td>'+$row[0]+\n'</td></tr>';