Problem with ($q->fetchInto($row)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • richm
    New Member
    • Feb 2007
    • 2

    Problem with ($q->fetchInto($row)

    Greetings,
    When I execute this code the table appears as [Book | Year Published | Author] and nothing else. I get no errors from Apache2.2 or MySQL.I am using Windows xp Home edition, English. If I use viewsource the table reads <tr><td><?= $row[0] ?></td><td><?= $row[1] ?></td><td><?= $row[2] ?></td></tr> etc. I have tapped all resources such as thescripts,mysq l ref,php.net,Pea r and many forums trying to solve the mystery. The code is from oreillys "Programmin g PHP Second Edition." Example 8-1. Display Book Information page 199. Any help would be appreciated.
    Sincerely, Richard M.

    code:
    [php]
    <html><head><ti tle>Library Books</title></head>
    <body>
    <table border=1>
    <tr><th>Book</th><th>Year Published</th><th>Author</th></tr>
    <?php
    // connect
    require_once('D B.php');
    $db = DB::connect("my sql://root:rich@local host/library");
    if (DB::iserror($d b)) {
    die($db->getMessage() );
    }
    // issue the query
    $mysql = "SELECT books.title,boo ks.pub_year,aut hors.name
    FROM books, authors
    WHERE books.authorid= authors.authori d
    ORDER BY books.pub_year ASC";
    $q = $db->query($mysql );
    if (DB::iserror($q )) {
    die($q->getMessage() );
    }
    error_reporting (E_ALL);
    ini_set('error_ reporting', E_ALL);
    // generate the table
    while ($q->fetchInto($row )) {
    ?>
    <tr><td><?= $row[0] ?></td>
    <td><?= $row[1] ?></td>
    <td><?= $row[2] ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </body></html>[/php]


    Read the Posting Guidelines before you post in this forum!

    Especially the part about enclosing code within [php] or [code] tags!!

    moderator
    Last edited by ronverdonk; Feb 19 '07, 07:54 PM. Reason: code tags!!!
  • cassbiz
    New Member
    • Oct 2006
    • 202

    #2
    Have you populated the database?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      [PHP]
      ?>
      <tr><td><?= $row[0] ?></td>
      <td><?= $row[1] ?></td>
      <td><?= $row[2] ?></td>
      </tr>
      [/PHP]

      This would be a problem on PHP 5.2.

      I'm not sure if <?= is used in earlyer versions of PHP but I do know that (by default) PHP 5 will not accept this.

      I would try rewriting this as

      [PHP]
      ?>
      <tr><td><?php echo $row[0]; ?></td>
      <td><?php echo $row[1]; ?></td>
      <td><?php echo $row[2]; ?></td>
      </tr>
      [/PHP]

      Comment

      Working...