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
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,,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.

<html><head><title>Library Books</title></head>
<table border=1>
<tr><th>Book</th><th>Year Published</th><th>Author</th></tr>
// connect
$db = DB::connect("mysql://root:rich@localhost/library");
if (DB::iserror($db)) {
// issue the query
$mysql = "SELECT books.title,books.pub_year,
FROM books, authors
WHERE books.authorid=authors.authorid
ORDER BY books.pub_year ASC";
$q = $db->query($mysql);
if (DB::iserror($q)) {
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>

Read the Posting Guidelines before you post in this forum!

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

Feb 19 '07 #1
Share this Question
Share on Google+
2 Replies

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

Expert 5K+
P: 5,058
<tr><td><?= $row[0] ?></td>
<td><?= $row[1] ?></td>
<td><?= $row[2] ?></td>

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

<tr><td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
Feb 20 '07 #3

Post your reply

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