By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

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

P: 2
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,mysql ref,php.net,Pear and many forums trying to solve the mystery. The code is from oreillys "Programming PHP Second Edition." Example 8-1. Display Book Information page 199. Any help would be appreciated.
Sincerely, Richard M.

code:
[php]
<html><head><title>Library Books</title></head>
<body>
<table border=1>
<tr><th>Book</th><th>Year Published</th><th>Author</th></tr>
<?php
// connect
require_once('DB.php');
$db = DB::connect("mysql://root:rich@localhost/library");
if (DB::iserror($db)) {
die($db->getMessage());
}
// issue the query
$mysql = "SELECT books.title,books.pub_year,authors.name
FROM books, authors
WHERE books.authorid=authors.authorid
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
Feb 19 '07 #1
Share this Question
Share on Google+
2 Replies


cassbiz
100+
P: 202
Have you populated the database?
Feb 19 '07 #2

Atli
Expert 5K+
P: 5,058
[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]
Feb 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.