我是数据库和PHP的新手,所以我对它们的集成了解非常有限。我的网站上显示了一个列表,每个项目都有一个链接到模式的按钮。我正在尝试使每个模式都与列出的项目的ID相对应。相反,它仅显示数据库列表中的最后一项。
我尝试添加从在线搜索中看到的代码,但是似乎没有任何效果。我想避免AJAX,JS和JQuery。我真的不认为这需要它。似乎只是语法错误。
<div class="recentUploads col-md-8">
<!-- Magic Key --- CONNECTS or PLUGS-IN to the DATABSE -->
<?php include("_inc/database_key.php"); ?>
<!-- REQUEST specific information -->
<?
$sql = "SELECT * FROM `comic book collection` ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<!-- DISPLAY that specific information -->
<?php
echo '<div class="comic_book_card row">';
$id=$row["id"];
echo '<div class="cover col-3"><img style="width: 100%;" src="'.$row["picture"].'"></div>';
echo '<div class="comic-info col-8">';
echo '<h2>#'.$row["issue"].' '.$row["title"].'</h2>';
echo '<h6>'.$row["publisher"].' | '.$row["event"].'</h6>';
echo '<h6>'.$row["month"].' '.$row["day"].', '.$row["year"].'</h6>';
echo '<button id="modal-btn" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#details" >More Info</button>';
echo '<form><input type="hidden" id="id" name="id" value="'.$row["id"].'"</form>';
echo '</div>';
echo '</div>';
?>
<!-- IM DONE - CLOSE the connection -->
<?php
}
} else {
echo "0 results";
}
$conn->close();
?>
</div>
细节
×
“ allowfullscreen>
关
答案 0 :(得分:0)
尝试使用此代码:-
<div class="recentUploads col-md-8">
<?php include("_inc/database_key.php"); ?>
<?
$sql = "SELECT * FROM `comic book collection` ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$output="";
while($row = $result->fetch_assoc()) {
$id=$row["id"];
$output.='<div class="comic_book_card row">
<div class="cover col-3"><img style="width: 100%;" src="'.$row["picture"].'"></div>
<div class="comic-info col-8">
<h2>#'.$row["issue"].' '.$row["title"].'</h2>
<h6>'.$row["publisher"].' | '.$row["event"].'</h6>
<h6>'.$row["month"].' '.$row["day"].', '.$row["year"].'</h6>
<button id="modal-btn" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#details" >More Info</button>
<form><input type="hidden" id="id" name="id" value="'.$row["id"].'"/></form>
</div></div>';
?>
}
</div>
<?php echo $output; ?>