尝试访问CDID
以在查询中进行设置,然后稍后使用GET在下一页上检索它。
我总是觉得INNER JOIN cdreview ON cdreview.CDID=cd.CDID
会合并CDID,因为它们是相同的值,然后我可以通过在查询中将其设置为$cdid = $row['CDID'];
来访问该值,但我总是收到Undefined index: CDID
错误消息。
我是菜鸟,因此可以提供任何帮助。
<?php
require_once 'database_conn.php';
$userid = $_SESSION['userSession'];
$sql = "SELECT cdreview.reviewDate, cdreview.reviewText, cd.CDTitle FROM cd
INNER JOIN cdreview ON cdreview.CDID=cd.CDID AND cdreview.userID='$userid' ORDER BY cdreview.reviewDate;" or die;
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)){
$date = $row['reviewDate'];
$album = $row['CDTitle'];
$review = $row['reviewText'];
$cdid = $row['CDID'];
echo"<table align='center'>
<tr align='center'>
<td colspan='5'>
<h2>View All Reviews</h2>
</td>
</tr>
<tr align='center'>
<th>Date</th>
<th>Album</th>
<th>Reviews</th>
<th>Edit Review</th>
<th>Delete Review</th>
</tr>
<tr align='center'>
<td>$date</td>
<td>$album</td>
<td>$review</td>
<td><a href=\"album_reviews.php?id=$cdid\"></a></td>
<td><a href=\"review.php?id=$cdid\"></a></td>
</tr>
</table>";
}
} else {
echo "<script>alert('You have not left any reviews!')</script>";
echo "<script>window.open('home.php', '_self')</script>";
}
mysqli_close($conn);
?>
最佳答案
您正在尝试获取未选择的值
$date = $row['reviewDate'];
$album = $row['CDTitle'];
$review = $row['reviewText'];
$cdid = $row['CDID'];
但您只选择
SELECT cdreview.reviewDate, cdreview.reviewText, cd.CDTitle from
您的选择中没有CDID列