i want to create an html table from a mariadb database. I dont know how many columns each Database table will end up with.
So as i dont know how many columns i have, i came up with this:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles/global.css">
</head>
<body>
<?php
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//query
$sql="SELECT * FROM news ORDER BY author";
$result=mysqli_query($con,$sql);
$counter = 0;
while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo $counter;
echo nl2br("\n");
?>
<table>
<thead>
<?php
if($counter==0){ ?>
<tr>
<th><?php echo implode("</th><th>", array_keys($row)); ?>
</th>
</tr>
}
</thead>
<tbody>
<?php
if($counter>=0){ ?>
<tr>
<td><?php echo implode("</td><td>", $row); ?>
</td>
</tr>
}
</tbody>
</table>
<?php
$counter ++;
}
mysqli_free_result($result);
mysqli_close($con);
?>
</body>
</html>
The problem is that the table wont fill with more than the first row.
Additionally i have get the error
Parse error: syntax error, unexpected end of file in E:\xampp\htdocs\test.php on line 58 Blockquote
The Error disappears when i enter two curly braces "}}" after the while loop, it will present the following:
I dont know why there are the curly braces in the browser as seen in the picture.
EDIT: I edit the thread because it was marked as duplicate to parsing and syntax errors, though my main problem is the creation of the table with unknown number of columns.
Any idea how to solve this? Thank you guys!