correction-ulysse #2
@@ -1,2 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
// TODO
|
|
||||||
|
$table = filter_input(INPUT_GET, 'table', FILTER_VALIDATE_INT);
|
||||||
|
$tableSaisie = filter_input(INPUT_GET, 'table', FILTER_UNSAFE_RAW);
|
||||||
|
$tableSaisie = is_string($tableSaisie) ? trim($tableSaisie) : '';
|
||||||
|
|
||||||
|
$lignes = [];
|
||||||
|
$messageErreur = '';
|
||||||
|
|
||||||
|
if ($tableSaisie !== '') {
|
||||||
|
if ($table === false || $table === null) {
|
||||||
|
$messageErreur = 'Veuillez saisir un entier valide.';
|
||||||
|
} else {
|
||||||
|
for ($multiplicateur = 1; $multiplicateur <= 10; $multiplicateur++) {
|
||||||
|
$lignes[] = [
|
||||||
|
'multiplicateur' => $multiplicateur,
|
||||||
|
'resultat' => $table * $multiplicateur,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,23 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
</head>
|
<title>Exercice 2</title>
|
||||||
<body>
|
</head>
|
||||||
<main>
|
<body>
|
||||||
<h4>Table de multiplication</h4>
|
<main>
|
||||||
<form method="GET">
|
<h4>Table de multiplication</h4>
|
||||||
<input type=number name="table" placeholder="table">
|
<form method="GET">
|
||||||
<button type="submit">ENVOYER</button>
|
<input
|
||||||
</form>
|
type="number"
|
||||||
</main>
|
name="table"
|
||||||
</body>
|
placeholder="table"
|
||||||
|
value="<?php echo htmlspecialchars($tableSaisie, ENT_QUOTES, 'UTF-8'); ?>"
|
||||||
|
>
|
||||||
|
<button type="submit">ENVOYER</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php if ($messageErreur !== '') : ?>
|
||||||
|
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($table !== false && $table !== null) : ?>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($lignes as $ligne) : ?>
|
||||||
|
<li>
|
||||||
|
<?php echo htmlspecialchars((string) $table, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
x
|
||||||
|
<?php echo htmlspecialchars((string) $ligne['multiplicateur'], ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
=
|
||||||
|
<?php echo htmlspecialchars((string) $ligne['resultat'], ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user