I am new to databases and PHP, so my knowledge of their integration is extremely limited. I have a list showing on my site and each item has a button that links to a modal. I am trying to have each modal open up correspond with the id of the item listed. Instead, it is only showing the last item in the database list.
I have tried adding code that I have seen from online searches, but nothing seems to work. I want to avoid AJAX, JS, and JQuery. I don't really think that it needs that. It seems to just be a syntax error.
<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>
Details × " allowfullscreen> CloseTry This Code :-
<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; ?>