Answer the question
In order to leave comments, you need to log in
How to set up auto-completion of a product template in PHP from the database (via PDO)?
The task is to set up a product card php template so that it is filled from the database. Those. when you click on a product of interest in the catalog, a product card template opens, which is filled from the database. The base is connected via PDO. Help me figure out how to pass information about which product is selected to the template in order to make a selection, for example, by id from an array.
My catalog page is configured like this:
(lines from the database file)
$sql = 'SELECT * FROM goods';
$statement = $pdo->query($sql);
$goods = $statement->fetchAll(PDO::FETCH_ASSOC);
<?php
foreach($goods as $good_itm) {
?>
<div class="product">
<a href="/pages/product
echo $good_itm['id'] .php">
<img src="/img/
echo $good_itm['image'];
"></a>
</div>
<?php
}
?>
Answer the question
In order to leave comments, you need to log in
I assume that for each product that should be filled in, you need to pass an identifier, after which you make a selection by this identifier and fill it with data.
$id = {id товара};
$statement = $pdo->prepare("SELECT * FROM goods WHERE id = ?");
$statement->execute([$id]);
$good = $statement->fetch(PDO::FETCH_ASSOC);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question