1

I am trying to include a separate snippet of code to fetch data from MySQL tables. My page code:

<?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>

My section-grabinfo.php page:

<?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>

Basically my problem is that section-grabinfo.php and footer.php are not being included on the main page. Please keep in mind that this worked completely when I had this on my laptop computer (not the server I'm currently working with). Thank you.

15
  • By the way, the "THIS IS A TEST" prints out fine. Commented Jul 7, 2016 at 6:16
  • So what is wrong exactly ? Commented Jul 7, 2016 at 6:16
  • section-grabinfo.php and footer.php are not being included on the main page. Commented Jul 7, 2016 at 6:17
  • We need your directory structure Commented Jul 7, 2016 at 6:17
  • 1
    why are you including secondary-article.php file in loop? Commented Jul 7, 2016 at 6:20

1 Answer 1

1

If it is really an including trouble, you could try to include this way

<?php include(__DIR__.'/head.php'); ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.