Mohamed Athif
Mohamed Athif

Reputation: 478

unexpected end of file and when solved doesn't work

This piece of code is giving me unexpected end of file. I don't know what's wrong. When I change the : at the end the issue of error is gone but the code stops working. It no longer fetches me any data. Also when I copy the code to jsfiddle I get the closing </section> tag and the closing </div> tag, second most from last in red color. Any idea why? Are the tags in wrong order?

<?php while ($r = $q->fetch()): ?>

here is the full code I'm working on if anyone is interested or got any clues.

<section id="portfolio" class="two">
  <div class="container">

    <header>
      <h2>Latest Answers</h2>
    </header>

    <?php
require_once 'dbconfig.php';

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    echo "Connected to $dbname at $host successfully.";
    $sql = "SELECT * 
            FROM as_questions 
            WHERE Answer IS NOT NULL and Answer != ''";



    $q = $conn->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);

} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
      <table>
        <?php while ($r = $q->fetch()): ?>
          <div class="span3 tiny">
            <div class="pricing-table-header-tiny">
              <h1 id="h1q"><?php echo htmlspecialchars($r['Question']);?></h1>


            </div>
            <div>
              <div class="pricing-table-features">
                <p id="dassp2">
                  <?php echo htmlspecialchars($r['Answer'])?>
                </p>
              </div>
              <div>
                <p id="Dassp">Answered by:
                  <?php echo htmlspecialchars($r['Doctor'])?>
                </p>
              </div>
            </div>

          </div>

  </div>
  <div id="qref">
    <a href="#" id="s">More Answers</a>
  </div>
</section>

Upvotes: 0

Views: 43

Answers (1)

LuckyLue
LuckyLue

Reputation: 158

while (expr):
    statement
    ...
endwhile;

You need close your loop - more info here http://php.net/manual/en/control-structures.while.php

Upvotes: 1

Related Questions