I have a question:
In PHP, HTML and MySQL I have made an overview of products (data from database) Now each product in this list has a more info button. I want, when I click more info, that a new page is opened and that page should show more info about that product. How do I make it work that it only shows the info of that particular product?
This is the current code of the table with the overview:
<div class="col-xs-2">
</div>
<div class="col-xs-4">
<h4 class="product-name"><strong> Producten</strong></h4><h4><small></small></h4>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong>Datum binnenkomst</strong></h6>
</div>
<div class="col-xs-4">
<h6><strong>Datum uitgave</strong></h6>
</div>
<div class="col-xs-2">
</div>
</div>
</div>
<hr>
<?php
include("connection.php");
$sql = "SELECT * FROM bedrijven";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo'
<div class="row">
<div class="col-xs-2"><img class="img-responsive" style="max-height:80px;" src="' . $row["KVK"] . '">
</div>
<div class="col-xs-4">
<h4 class="product-name"><strong> '. $row["Bedrijfsnaam"] .' </strong></h4><h4><small>'. $row["Klantnummer"] .'</small></h4>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong>'. $row["BStraatnaam"] .'</strong></h6>
</div>
<div class="col-xs-4">
<h6><strong>'. $row["BHuisnummer"] .'</strong></h6>
</div>
<div class="col-xs-2">
<a href="Moreinfo.php"> <button type="button" class="btn btn-link btn-xs">
More info
</button></a>
</div>
</div>
</div>
<hr>';
}
} else {
echo "0 results";
}
$conn->close();?>
I hope someone would help me.
It would be nice to learn more and new things;)
If you want to split up results only print out what you want to show. You can do selective queries with LIMIT
(for a range) or just make sure you only get one result usually done by using a unique identifier (an auto-incremented ID field) and WHERE id = 1
.
And in PHP we can use $_GET['page']
, to get the page parameter from an url like:
domain.com/somepage?page=2
However remember that this is easily edited by the end user in the location bar and thus should be properly handled in PHP before using it in a SQL query to avoid SQL injection. It be checking with PHP's is_number
or using something like prepared statements