Skip to content

Instantly share code, notes, and snippets.

@julp
Last active October 2, 2019 17:29
Show Gist options
  • Save julp/909eee4b3826f38e5746d404bb880d12 to your computer and use it in GitHub Desktop.
Save julp/909eee4b3826f38e5746d404bb880d12 to your computer and use it in GitHub Desktop.
[OC] Jours/horaires d'ouverture/fermeture magasin
<?php foreach (range(1, 7) as $jour): ?>
<?php foreach (['ouverture', 'fermeture'] as $of): ?>
<select name="<?= $of ?>[<?= $jour ?>]">
<option value="Fermé">Fermé</option>
<option value="01:00:00">1 H00</option>
<option value="02:00:00">2 H00</option>
<option value="03:00:00">3 H00</option>
</select>
<?php endforeach ?>
<?php endforeach ?>
<?php
$insert = $bdd->prepare('INSERT INTO horaires (id_entreprise, jour, opening, ouverture, fermeture) VALUES (:id_entreprise, :jour, :opening, :ouverture, :fermeture)');
$insert->bindParam(':id_entreprise', $_POST['id_entreprise'], PDO::PARAM_STR);
$insert->bindParam(':jour', $jour, PDO::PARAM_STR);
$insert->bindParam(':opening', $opening, PDO::PARAM_INT);
$insert->bindParam(':ouverture', $ouverture, PDO::PARAM_STR);
$insert->bindParam(':fermeture', $fermeture, PDO::PARAM_STR);
foreach ($_POST['ouverture'] as $jour => $ouverture) {
$fermeture = $_POST['fermeture'][$jour];
$opening = intval(!in_array('Fermé', [$ouverture, $fermeture]));
/*if (!$opening) { $ouverture = $fermeture = NULL; }*/
$insert->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment