Any idea what's going on and how to fix this?
Thanks in advance
Code:
Code: Select all
<?php // query.php
$db_hostname = '127.0.0.1';
$db_database = 'lab6';
$db_username = 'root';
require_once 'lab-exercise10-5.php';
$db_server = mysql_connect($db_hostname, $db_username);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database) or die("Unable to select database: " . mysql_error());
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
for ($j = 0 ; $j < $rows ; ++$j)//Why is it displaying double the results?...
{
$row = mysql_fetch_row($result);
echo 'Author: ' . $row[0] . '<br />';
echo 'Title: ' . $row[1] . '<br />';
echo 'Category: ' . $row[2] . '<br />';
echo 'Year: ' . $row[3] . '<br />';
echo 'ISBN: ' . $row[4] . '<br /><br />';
}
?>Code: Select all
Author: Mark Twain
Title: The Adventures of Tom Sawyer
Type: Fiction
Year: 1876
Pages: 100
ISBN: 9781598184891
Author: Jane Austen
Title: Pride and Prejudice
Type: Fiction
Year: 1811
Pages: 124
ISBN: 9780582506206
Author: Charles Darwin
Title: The Origin of Species
Type: Non-Fiction
Year: 1856
Pages: 95
ISBN: 9780517123201
Author: Charles Dickens
Title: The Old Curiosity Shop
Type: Fiction
Year: 1841
Pages: 134
ISBN: 9780099533474
Author: William Shakespeare
Title: Romeo and Juliet
Type: Play
Year: 1594
Pages: 123
ISBN: 9780192814968
Author: Test Testing
Title: Another Test
Type: Test
Year: 1337
Pages: 666
ISBN: 9780192814967
Author: Mark Twain
Title: The Adventures of Tom Sawyer
Category: Fiction
Year: 100
ISBN: 1876
Author: Jane Austen
Title: Pride and Prejudice
Category: Fiction
Year: 124
ISBN: 1811
Author: Charles Darwin
Title: The Origin of Species
Category: Non-Fiction
Year: 95
ISBN: 1856
Author: Charles Dickens
Title: The Old Curiosity Shop
Category: Fiction
Year: 134
ISBN: 1841
Author: William Shakespeare
Title: Romeo and Juliet
Category: Play
Year: 123
ISBN: 1594
Author: Test Testing
Title: Another Test
Category: Test
Year: 666
ISBN: 1337