1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <?php
$rows = array();
$selected = array();
$message = '';
// on s'assure que les données récupérées sont correctes
if (( ! empty($_POST['ok'])) && is_array($_POST['ok'])) {
$selected = array_filter($_POST['ok'], function($p) { return (bool)intval($p); });
if ( ! empty($selected)) {
sort($selected);
$message = 'Les chiffres choisis sont : '.implode(', ', $selected);
$selected = array_flip($selected);
}
}
for($i = 1 ; $i <= 45 ; ++$i) {
// ligne
$rows[] = '<tr>';
// colonnes
for($j = 1 ; $j <= 9 ; ++$j) {
$checked = (isset($selected[$i])) ? ' checked="checked" ' : '';
$rows[] =
<<<HTML
<td align="center"><input type="checkbox" {$checked} name="ok[]" value="{$i}">{$i}</td>
HTML;
++$i;
}
$rows[] = '</tr>';
}
?>
<html>
<body>
<form action="dvp.php" method="post">
<table border="3" width="80" cellspacing="10" bordercolor="blue" bgcolor="orange" colspan="9">
<?php echo implode("\n", $rows); ?>
</table>
<input type="submit" value="Jouer">
</form>
<?php echo $message; ?>
</body>
</html> |