Php 无法从SQL数据库中获取post

Php 无法从SQL数据库中获取post,php,html,sql,Php,Html,Sql,您好,我正在尝试从我的sql中获取数据,其中包含id、post_作者、post_日期、post_内容、post_标题和post_状态 现在我对post.php的基本理解是 <?php require_once("../../includes/session.php"); ?> <?php require_once("../../includes/db_connection.php"); ?> <?php require_once("../../includes/fu

您好,我正在尝试从我的sql中获取数据,其中包含id、post_作者、post_日期、post_内容、post_标题和post_状态

现在我对post.php的基本理解是

<?php require_once("../../includes/session.php"); ?>
<?php require_once("../../includes/db_connection.php"); ?>
<?php require_once("../../includes/functions.php"); ?>
<?php
$post = "";
$id = 1;
// ^'will be using $_GET['id'] to get current post
find_post_by_id($id, $public=true);
?>
<?php include("../../includes/layouts/header.php") ?>

<div class="container post">
    <h1><?php echo htmlentities($post["post_title"]); ?></h1>
    <p>Auther & postdate n time</p>
    <hr class="hrpost">
    <div class="content">
        Content in form of the text
    </div>
</div>

<?php include("../../includes/layouts/footer.php") ?>
然后当我试图得到它时,它会说->

警告:D行13中的字符串偏移量“post_title”非法


为什么要这样做?我该如何修复它?

这可能就是你要找的

$post = find_post_by_id($id, $public=true);

如果查询没有返回您需要的内容,请确保打印或记录查询。然后在mysql控制台上运行该查询,仔细检查它是否确实返回了一些内容。

$post似乎不是数组,可能返回null。尝试var_dump($post);抱歉,这是我编辑的@Ekin:)的mysqli_fetch_assoc,如果是我放在哪里的话,谢谢!它返回了TEST:)作为帖子标题whas alot@timhysniu表示感谢
$post = find_post_by_id($id, $public=true);