PHP include();不包括文件

时间:2016-07-07 06:14:51

标签: php html

我试图包含一个单独的代码片段来从MySQL表中获取数据。我的页面代码:

<?php session_start(); ?>
<html>
    <?php include('head.php'); ?>
    <body>
        <?php include('navigation.php'); ?>
        <div id="container">
        <?php
            $section = "Movies";
            print "THIS IS A TEST";
            //$_SESSION['sectiontemp'] = $section;
            include('section-grabinfo.php');
            include('footer.php');
        ?>
        </div>
    </body>
</html>

我的 section-grabinfo.php 页面:

<?php
            print "THIS IS A TEST";
            $sql = mysqli_query($conn, "SELECT * FROM article JOIN person ON article.author=person.id WHERE section='".$section."' AND status=1 ORDER BY aid DESC LIMIT 1;");
            if ($sql == 'false') {
                print "SQL doesn't work";
            }
            elseif ($sql == 'true') {
                print "Works all fine";
            }
            else {
                print "Wrong code.";
            }
            while ($row = mysqli_fetch_assoc($sql)) {
                $title = $row['title'];
                $preview = $row['preview'];
                $author = $row['name'];
                $person_id = $row['author'];
                $id = $row['id'];
                $username = $row['username'];
                include('featured-article.php');
            }
            //LEAVE SPACE FOR ADS
?>
<div id="secondaryArticleSection">
<?php
            $sql2 = mysqli_query($conn, "SELECT * FROM article JOIN person ON article.author=person.id WHERE aid<(SELECT max(aid) FROM article WHERE section='."$section."' AND status=1) AND section='".$section."' AND status=1 ORDER BY aid DESC;");
            while ($row = mysqli_fetch_assoc($sql2)) {
                $title = $row['title'];
                $preview = $row['preview'];
                $author = $row['name'];
                $person_id = $row['author'];
                $id = $row['id'];
                $username = $row['username'];
                include('secondary-article.php');
            }
?>
</div>

基本上我的问题是主页上没有包含 section-grabinfo.php footer.php 。请记住,当我在笔记本电脑上使用时(这不是我目前正在使用的服务器),这完全有效。谢谢。

1 个答案:

答案 0 :(得分:1)

如果真的包含麻烦,你可以尝试这种方式

<?php include(__DIR__.'/head.php'); ?>