voici le code qui génère le tableau:
Code : Tout sélectionner
<form method="post" name="validerclient">
<div class="container">
<table class="styled-table">
<thead>
<tr>
<th>Nom</th>
<th>Prénom</th>
<th>Téléphone</th>
<th>Mail</th>
<th>Quantité</th>
<th>Passage Valider</th>
<th>Valider</th>
<th></th>
</tr>
</thead>
<tbody>
<?php if($clients != ""): ?>
<?php foreach ($clients as $client): ?>
<tr>
<td><?= $client['nom'] ?></td>
<td><?= $client['prenom'] ?></td>
<td><?= $client['phone'] ?></td>
<td><?= $client['mail'] ?></td>
<td><input type="text" name="quantity" style="width:50px;"></td>
<td><?= count($scores) ?></td>
<td><input type="submit" value="Valider" name="valider"></td>
<td><input type="hidden" name ="client_id" value="<?= $client['id'] ?>" ></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</form>
Code : Tout sélectionner
if(isset($_POST['valider'])){
$id_client = $_POST['client_id'];
for ($i = 0; $i < $_POST['quantity']; $i++){
$query = $db->prepare('INSERT INTO carte_client (date, id_client) VALUES (:date, :id_client)');
$result = $query->execute([
'date' => $date,
'id_client' => $_POST['client_id'],
]);
$points = $db->query("
SELECT cc.id_client, cc.date, a.nom, a.id, a.prenom
FROM carte_client cc
LEFT JOIN client a ON a.id = cc.id_client
WHERE cc.id_client = $id_client
")->fetchAll();
if(count($points)>= 25){
$delete = $db->query("
DELETE FROM carte_client
WHERE id_client = $id_client
LIMIT 25
")->fetchAll();
if (!$result) {
$errors[$query->errorCode()] = $query->errorInfo();
}
else if (empty($errors)) {
$errors[] = sprintf('Une réduction a été notée pour le prochain passage !');
if (intdiv($_POST['quantity'],25) >= 1){
for($y = 0; $y < intdiv($_POST['quantity'],25); $y++){
$ajout = $db->prepare("INSERT INTO complet (id_client) VALUES (:id_client)");
$complet = $ajout->execute([
'id_client' => $id_client,
]);
}
}else{
for($y = 1; $y <= intdiv(count($points),25); $y++){
$ajout = $db->prepare("INSERT INTO complet (id_client) VALUES (:id_client)");
$complet = $ajout->execute([
'id_client' => $id_client,
]);
}
}
}
}
}
$scores = $db->query("
SELECT cc.id_client, cc.date, a.nom, a.id, a.prenom
FROM carte_client cc
LEFT JOIN client a ON a.id = cc.id_client
WHERE cc.id_client = $id_client
")->fetchAll();
if(count($scores)!="0"){
foreach ($scores as $score):
$poin .= $score['date'];
endforeach;
}
else{
foreach ($points as $point):
$poin .= $point['date'];
endforeach;
}
}