如何显示mysql PHP中的数据不是在表中,而是在段落中



正如标题中所写的,我希望数据显示在段落中,而不是表中。请任何人帮助我。这是我的工作代码,数据显示在表格中。但我希望显示在段落中,而不是tr/th中。

<!DOCTYPE html>
<html lang="pl-PL">
<head>
</head>
<body>
<table>
<tr>
<th>Content</th>
</tr>    
<?php
session_start();
$username = "";
$email    = "";
$errors = array();
$_SESSION['success'] = "";
$mysqli = mysqli_connect('localhost', 'root', '', 'cms');
?>
<?php
$query ="SELECT * FROM articles";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()){
echo "<tr><td>" .$row['article_content'] ."</td><tr>";
}
}
?>
</table>
</body>
</html>

只需更改HTML即可删除与表相关的代码,并将其替换为段落元素。请注意,session_start在使用现有代码时会失败,因为它将尝试发送标头,但PHP在遇到文档中的HTML时就已经发送了标头。因此,您需要将session_start代码移动到文件的开头。

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="pl-PL">
<head>
</head>
<body>
<h1>Content</h1>  
<?php
$username = "";
$email    = "";
$errors = array();
$_SESSION['success'] = "";
$mysqli = mysqli_connect('localhost', 'root', '', 'cms');
//Create the select query
$query ="SELECT * FROM articles"; 
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
//Loop through results
while($row = $result->fetch_assoc()){
echo "<p>" .$row['article_content'] ."</p>";
}
}
?>
</body>
</html>

试试这个:

echo "<p>" .$row['article_content'] ."</p>";

从文件中删除表标记。