我想在我的php页面上只显示一个选定的结果.
这是我的PHP代码:
$bookdetsql = "
SELECT b.bookISBN
, b.bookTitle
, b.bookYear
, b.catID
, b.pubID
, p.pubName
, p.location
, c.catDesc
, b.bookPrice
FROM nbc_book b
LEFT
JOIN nbc_category c
ON b.catID = c.catID
LEFT
JOIN nbc_publisher p
ON b.pubID = p.pubID
";
$bookdetrs = mysqli_query($conn, $bookdetsql) or die(mysqli_error($conn));
$bookdetnum = mysqli_num_rows($bookdetrs);
if($bookdetnum >= 1 ){
echo "<div style='margin: 0 0 10px 0; font-weight: bold;'>$bookdetnum record(s) found!</div>";
while ($row = mysqli_fetch_assoc($bookdetrs)) {
echo "<tr>";
echo "<td><center>" . $row['bookTitle']."</a></center></td>";
echo "<td><center>" . $row['bookYear']."</center></td>";
echo "<td><center>" . $row['catDesc']."</center></td>";
echo "<td><center>" . $row['bookPrice']."</center></td>";
echo "<td><center>" . $row['pubName']."</center></td>";
echo "<td><center>" . $row['location']."</center></td>";
echo "</tr>";
}
} else {
echo "<b>Books not found!</b>";
}
实际上这个代码实际上是显示整个记录列表.我只希望它显示我在第一个php页面上点击的所选记录.
最佳答案 你是如何从第一页获得价值的? GET还是POST?
当您有值时,可以在SELECT语句中添加where子句
$bookdetsql = "SELECT bookISBN, bookTitle, bookYear, nbc_book.catID, nbc_book.pubID, pubName, location, catDesc, bookPrice
FROM nbc_book
LEFT JOIN nbc_category ON nbc_book.catID = nbc_category.catID
LEFT JOIN nbc_publisher ON nbc_book.pubID = nbc_publisher.pubID
WHERE bookISBN = '" . $_GET["bookISBN"] . "'";