douwen8424 2018-10-31 14:03
浏览 40
已采纳

如何显示来自mysql的数据PHP不在表中但在段落[复制]中

This question already has an answer here:

As written in the tittle I would like the data to be displayed in paragraph not in a table. Can please anyone help me. This is my working code, data is displayed in a table. BUT I would like to be displayed in paragraphs not in 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>
</div>
  • 写回答

2条回答 默认 最新

  • donglingyi4679 2018-10-31 14:06
    关注

    Just change your HTML to remove the table-related code, and replace it with paragraph elements. Note that your session_start is going to fail with your existing code as it will attempt to send headers but PHP will have already sent headers as soon as it encountered the HTML in the document. So you need to move the session_start code to the beginning of the file.

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度