initial working solution. Very plain, no style. Only amount of numbers to generate...
authordanix <danix@danix.xyz>
Sun, 10 Mar 2019 10:41:46 +0000 (11:41 +0100)
committerdanix <danix@danix.xyz>
Sun, 10 Mar 2019 10:41:46 +0000 (11:41 +0100)
index.php

index 2372dfaa0b55a1606272ed8ee58142cb4088e741..019ebd2960d63f802796181e3bbbaa93b1229b13 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,14 +1,19 @@
 <?php
-$numbers = array();
-$i=0;
-while ($i<=5) {
-       $rnd_num = random_int(1, 90);
-       if (! in_array($rnd_num, $numbers)) {
-               $numbers[] = $rnd_num;
+function generator($howmany = 6) {
+       $numbers = array();
+       $i = 0;
+       $max = $howmany - 1;
+
+       while ($i <= $max) {
+               $rnd_num = random_int(1, 90);
+               if (! in_array($rnd_num, $numbers)) {
+                       $numbers[] = $rnd_num;
+               }
+               $i++;
        }
-       $i++;
+       sort($numbers);
+       return $numbers;
 }
-sort($numbers);
 ?>
 <!DOCTYPE html>
 <html lang="it_IT">
@@ -24,8 +29,11 @@ sort($numbers);
 <body>
        <div id="wrapper">
                <div id="header">
-                       <header></header>
-               </div>
+                       <header>
+                               <h1>GET LUCKY&excl;</h1>
+                               <h2>generatore di numeri fortunati</h2>
+                       </header>
+               </div> <!-- #header -->
 
                <div id="main" role="main">
 
@@ -33,25 +41,37 @@ sort($numbers);
                                <div id="content">
                                        <article>
                                                <header>
-                                                       <h2>I tuoi numeri fortunati</h2>
+                                                       <h3>Ecco i tuoi numeri</h3>
                                                </header>
+<?php
+       if (!empty($_POST["howmany"])) {
+               $num = $_POST["howmany"];
+        } else {
+               $num = 6;
+        }
+       $list = generator($num);
+?>
                                                <div class="numbers">
-                                                       <div id="1"><?php echo $numbers[0]; ?></div>
-                                                       <div id="2"><?php echo $numbers[1]; ?></div>
-                                                       <div id="3"><?php echo $numbers[2]; ?></div>
-                                                       <div id="4"><?php echo $numbers[3]; ?></div>
-                                                       <div id="5"><?php echo $numbers[4]; ?></div>
-                                                       <div id="6"><?php echo $numbers[5]; ?></div>
-                                               </div>
+                                                       <?php 
+                                                       $num = $num -1;
+                                                       for ($i=0; $i <= $num ; $i++) : ?>
+                                                       <div id="<?php echo $i; ?>"><?php echo $list[$i]; ?></div>
+                                                       <?php endfor; ?>
+                                               </div> <!-- .numbers -->
                                        </article>
-                               </div>
+                               </div> <!-- #content -->
                        </div> <!-- /#container -->
 
-                       <aside></aside>
+                       <aside class="menu">
+                               <form action="" method="POST">
+                                       <input type="number" min="1" max="10" step="1" name="howmany" required>
+                                       <input type="submit">
+                               </form>
+                       </aside>
                </div> <!-- /#main -->
 
                <footer id ="footer">
-               </footer>
+               </footer> <!-- #footer -->
        </div> <!-- /#wrapper -->
 
 </body>