6
I have a somewhat disturbing problem, I have researched several ways, but found no solution.
Below the explanation:
A very simple system, it looks like a calendar, but within each day of the calendar,
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 clickable the number of the day.
being as follows:
With this system the Military can schedule the day he will eat in the kitchen.
The problem I’m having is that when it selects more than 1 day number the result appears all duplicated, like this:
Follow 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>
php checkbox.
<?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>";
}
?>
Give a print_r($_POST); see what returns to you...
– Sr. André Baill
The error is in the checkbox forach.. because you are doing two foreach.. so it doubles even :)
– Sr. André Baill
The problem is that the days have to be associated with the other checkbox
– Jorge B.
Once the question lock is finished, in about 45 minutes, please edit the question to change any kind of information that harms you, but without invalidating the answers. Thank you.
– Math