如何回显 MySQL Table 列中的内容

How to echo out content from a MySQL Table Column

一段时间以来,我一直试图创建一个管理面板视图,用户可以在其中插入内容,然后在网站上 posted。一种较小版本的 wordpress,目前主要用于私人和教育用途。但是,我无法从事物的管理面板视图中获取 post 发送到数据库的内容。它根本不会显示任何内容,这让我觉得我做的事情 非常重要 是错误的。

这是我得到的:(连接)

   <?php
session_start();

$adress = 'Host adress goes here';
$dbusername = 'Database username goes here';
$dbpassword = 'Database password goes here';

$anslutning = mysqli_connect($host, $dbusername, $dbpassword);
if (!$anslutning) die ("<br /><b>Can't connect to server</b>");

$anslutning->select_db('Database name goes here') or die ("Could not connect to database");

    ?>

而我目前无法使用的代码

<p class="welcometext">
    <?php

        $getContentQuery = "SELECT content FROM tblPages";

        if ($getContent = $anslutning->prepare($getContentQuery)) {



        $getContent->execute();
        $result = $anslutning->query($getContentQuery);

        while ($rows = mysql_fetch_array($result)) {

            echo $rows[2];


        }
    }




    ?>
</p>

**编辑:**我刚刚意识到它不会在 if 语句中回显任何内容,所以作为 PHP 的新手,我不确定它是否应该这样做,或者是否这就是 'while' 不起作用的原因。

EDIT2: 所以我得到了答案并给它开票。但是,我需要添加一些东西。虽然我写的东西从一开始就是错误的,但删除所有早期的 PHP 代码似乎可以解决问题(让故障排除开始吧!)。感谢大家的帮助和时间,只要我能弄清楚是什么问题,问题就解决了。

您正在回应似乎不存在的 $post。回显 $rows

 if ($getContent = $anslutning->prepare($getContentQuery)) {
     $getContent->execute();
     $content='';
     $getContent->bind_result($content);
     while ($getContent->fetch()) {
        echo $content;
     }
 }