CPJ18
Programmer
- Oct 9, 2013
- 1
I have 2 MySQL tables: Books and Reviews. The ISBN is the unique identifier. I need to display ALL reviews for a specific Book Title. My problem is that when a book title is clicked on the next page shows the Book information and the first record in the Reviews table. This happens for each Book Title. Only the first record in the Reviews table is displaying instead of the reviews for a specific title based on the ISBN. Here is my code:
<!DOCTYPE html>
<head>
<title>PHP Single Item DB data display</title>
</head>
<body>
<?php
$conn = new mysqli("localhost", "it6203", "it6203", "textbooks");
//host, user, password, database
if (mysqli_connect_errno()){
echo 'Cannot connect to database: ' .
mysqli_connect_error($conn);
}
else{
$query = "SELECT * from books a join reviews b where b.ISBN and a.ISBN='".$_GET["bookid"]."'";
$result = mysqli_query($conn, $query);
if (!$result) {
die("Invalid query: " . mysqli_error($conn));
}
else {
$info="";
$hastitle=false;
while($row = mysqli_fetch_array($result))
{
if (!$hastitle){
$info.="<h1>{$row['BookTitle']}</h1>";
$info.="<p>ISBN: {$row['ISBN']}</p>";
$info.="<p>Author(s): {$row['Authors']}</p>";
$info.="<p>Price: {$row['ListPrice']}</p>";
$info.="<p>Publish Date: {$row['PubDate']}</p>";
$info.="<p>Publisher: {$row['Publisher']}</p>";
$hastitle=true;
$info.="<p>Review: {$row['Content']}</p>";
}
}
echo $info;
mysqli_free_result($result);
}
mysqli_close($conn);
}
?>
</body>
</html>
Can anyone help me? Thank you in advance.
<!DOCTYPE html>
<head>
<title>PHP Single Item DB data display</title>
</head>
<body>
<?php
$conn = new mysqli("localhost", "it6203", "it6203", "textbooks");
//host, user, password, database
if (mysqli_connect_errno()){
echo 'Cannot connect to database: ' .
mysqli_connect_error($conn);
}
else{
$query = "SELECT * from books a join reviews b where b.ISBN and a.ISBN='".$_GET["bookid"]."'";
$result = mysqli_query($conn, $query);
if (!$result) {
die("Invalid query: " . mysqli_error($conn));
}
else {
$info="";
$hastitle=false;
while($row = mysqli_fetch_array($result))
{
if (!$hastitle){
$info.="<h1>{$row['BookTitle']}</h1>";
$info.="<p>ISBN: {$row['ISBN']}</p>";
$info.="<p>Author(s): {$row['Authors']}</p>";
$info.="<p>Price: {$row['ListPrice']}</p>";
$info.="<p>Publish Date: {$row['PubDate']}</p>";
$info.="<p>Publisher: {$row['Publisher']}</p>";
$hastitle=true;
$info.="<p>Review: {$row['Content']}</p>";
}
}
echo $info;
mysqli_free_result($result);
}
mysqli_close($conn);
}
?>
</body>
</html>
Can anyone help me? Thank you in advance.