Reputation: 43
I need to show some results in table, but the query data shows up to the table. Here is the code:
$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>";
The result is like this:
1234
№
It should look like this:
№
1
2
3
4
Upvotes: 0
Views: 140
Reputation: 103
Replace the "+" with "." The "+" is used to add values, the "." is used to concatenate strings
$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>";
or use the following
print "<tr><td>$row[0]</td></tr>";
Upvotes: 1