Pour l'instant j'ai réussi à faire un petit champ de recherche rudimentaire mais fonctionnel, et maintenant je souhaite que mes boutons Commander ajoutent les produits choisis à la commande, que cela s'ajoute visuellement sur la page mais que l'utilisateur puisse continuer à chercher d'autres produits les ajouter etc.
C'est ce que j'ai en tête mais je n'ai jamais vraiment fait quelque chose d'aussi avancé durant mes études (1ère année de BTS), c'est pourquoi je sollicite votre aide pour essayer d'avancer un peu (je n'ai aucune aide sur place).
Merci beaucoup aux personnes qui prendront le temps de m'aider !
<?php
$localhost = "localhost";
$username = "root";
$password = "";
$dbname = "bon_commande";
$con = new mysqli($localhost, $username, $password, $dbname);
if( $con->connect_error){
die('Error: ' . $con->connect_error);
}
// Variable de recherche
$recherche ="";
// Requêtes d'affichage et de recherche de produits
$sql = "SELECT id_produit,nomProduit,prixProduit,nom
FROM produit
INNER JOIN famille ON famille.id_famille=produit.id_famille
GROUP BY nomProduit";
if( isset($_GET['recherche']) ){
$recherche = mysqli_real_escape_string($con, htmlspecialchars($_GET['recherche']));
$sql=" SELECT id_produit,nomProduit,prixProduit,nom FROM produit
INNER JOIN famille ON famille.id_famille=produit.id_famille
WHERE nomProduit LIKE '%$recherche%'
GROUP BY id_produit";
}
$resultat = $con->query($sql);
$selection ='';
?>
<html>
<head>
<title>Recherche de produits</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<header>
<img src="./images/batimans.jpg" alt="" height="80px"/>
</header>
<div class="container">
</br>
<form method="GET">
<input type="text" placeholder="que cherchez vous ?" name="recherche">
<input type="submit" value="Recherche" name="btn" class="btn btn-sm btn-primary">
<a href="index.php"><button class="btn btn-outline-success" type="button">Retour</button></a>
<!-- à faire : liste déroulante pour sélection de famille de produits -->
</form>
<h2>Produits proposés</h2>
<table class="table table-striped table-responsive">
<tr>
<th>ID</th>
<th>nom</th>
<th>Famille</th>
<th>Prix</th>
<th><center><img src="./images/felche_bas.png" alt="" height="25px"/></center></th>
</tr>
<!-- Affichage des produits proposés -->
<?php
while($ligne = $resultat->fetch_assoc()){
?>
<tr>
<td><?php echo $ligne['id_produit']; ?></td>
<td><?php echo $ligne['nomProduit']; ?></td>
<td><?php echo $ligne['nom']; ?></td>
<td><?php echo $ligne['prixProduit']; ?>€</td>
<td><center><input type="button" value="Commander" name="btn" class="btn btn-sm btn-primary"></center></td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>