I have a somewhat disturbing problem, I've tried it in several ways, but I have not found a solution.
Below the explanation:
A very simple system, it looks like a calendar, but within each calendar day,
There are 3 fields in checkbox
to be clicked, in these fields I used the nomenclature of C, A, J (Coffee, Lunch and Dinner) and also made the number of the day clickable.
being as follows:
WiththissystemtheMilitarymanagestoschedulethedayhewilleatinthekitchen.
TheproblemI'mhavingisthatwhenitselectsmorethan1daynumbertheresultappearsallduplicate,likethis:
The following is the code below:
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Sistema de Arranchamento</title>
<?php
/*include "conectando.php"; */
date_default_timezone_set('America/Sao_Paulo');
$dates = date('Y/m/d');
$hoje = getdate(strtotime($dates));
$ultimoDia = cal_days_in_month(CAL_GREGORIAN,
$hoje['mon'],
$hoje['year']);
$primeiraSemana = (($hoje['wday'] + 1) -
($hoje['mday'] - ((int)($hoje['mday'] / 6) * 7))) % 7;
?>
<style>
td[data-semana="0"] { color: #000000; }
</style>
</head>
<body>
<h1>Estamos em <?= $hoje['year'] ?></h1>
<p><?= sprintf('Hoje é dia <strong>%0d / %0d</strong>, agora são %02d horas e %0d minutos.',
$hoje['mday'], $hoje['mon'], $hoje['hours'], $hoje['minutes'])
?></p>
<table border="1">
<tr>
<th>Dom</th>
<th>Seg</th>
<th>Ter</th>
<th>Qua</th>
<th>Qui</th>
<th>Sex</th>
<th>Sáb</th>
</tr>
<tr>
<form action="checkbox.php" method="post">
<?php
for($semana = 0; $semana < $primeiraSemana; ++$semana) {
echo '<td> </td>';
}
for($dia = 1; $dia < $ultimoDia; ++$dia) {
if( $semana > 6 ) {
$semana = 0;
echo '</tr><tr>';
}
echo "<td data-semana=\"$semana\"><center><font size='2px'/>";
echo "$dia <input type='checkbox' name='dia[]' value='$dia'> <center><input type='checkbox' name='opcao[]' value='C'>C <input type='checkbox' name='opcao[]' value='A'>A <input type='checkbox' name='opcao[]' value='J'>J</td>";
++$semana;
}
for(; $semana < 7; ++$semana) {
echo '<td> </td>';
}
?>
<?php
if( !empty( $_POST['dias'] ) ) {
foreach( $_POST['dias'] as $key => $value ) {
echo "<br />Semana $key<br />";
foreach( $value as $dias ) {
echo "$dias<br />";
}
}
}
?>
<input type=submit value="Arranchar">
</form>
</tr>
</table>
</body>
</html>
checkbox.php
<?php
// Verifica se usuário escolheu algum número
if(isset($_POST["dia"])){
if(isset($_POST["opcao"])){
echo "Você se arranchou para os dias:<BR>";
// Faz loop pelo array dos numeros
foreach($_POST["dia"] as $dia){
foreach($_POST["opcao"] as $numero){
echo " - " . $dia . " -" . $numero . "</BR>";
}
}
}
}
else
{
echo "Você não se arranchou para nenhum dia!<br>";
}
?>