Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- HTML Lapas kodejums-->
- <title> Nejauši skaitļi (PHP), Ikars Melnalksnis, 3DT-1 </title>
- <style>
- body {
- background: LightBlue;
- font-size: 30px;
- }
- /*3 Limeņa virsraksta stils*/
- h3 {
- text-weight: bold;
- text-decoration: underline;
- }
- /*Teksta lauka stils */
- p {
- font-weight: bold;
- text-decoration: underline;
- }
- /*Tabulas stils*/
- table {
- border: 2px solid black;
- }
- /*Tabulas sunu un rindu stils*/
- td,tr {
- border: 1px solid black;
- font-size: 20px;
- text-align: center;
- padding-left: 15px;
- padding-right: 15px;
- }
- button {
- margin-top: 15px;
- width: 100px;
- }
- </style>
- <script>
- function Atpakal() {
- window.history.back();
- }
- </script>
- <?php
- //Ciparu kopskaits ko iegūst no formas
- $ciklu_skaits = $_POST["skaitlu"];
- //Ja nav iegūta vērtība, tad noklusētā ir 40
- if ($ciklu_skaits == 0) $ciklu_skaits = 40;
- //Ciparu masivs
- $cipari = array();
- //Izvades tabula
- $izvade = "<table>";
- //For cikls kurs veiks ciklu_skaits ciklus
- for ($cikls = 0; $cikls < $ciklu_skaits; $cikls++) {
- //Masiva elements i iegūst nejaušu 1-100 vertibu
- $cipari[$cikls] = rand(1,100);
- }
- //Pievieno izvades elementam masiva elementus
- foreach ($cipari as $cikls => $value) {
- //Ja cikls skaitītājs ir dalāms ar 5
- if ($cikls % 5 == 0) {
- //Pievieno jaunu rindu ar pirmo sunu
- $izvade = $izvade . "</tr><tr><td>" . $value . "</td>";
- } else {
- //Savadak pievieno jaunu sunu
- $izvade = $izvade . "<td>" . $value . "</td>";
- }
- }
- //Izvades tabulai pievieno tabulas beigu tagus
- $izvade = $izvade . "</tr></table>";
- //Izvada tabulu
- echo "<h3>Gadījuma skaitļu ģenerēšana</h3><p>Atrastie ". $ciklu_skaits ." gadījuma skaitļi</p>". $izvade;
- echo "<button type='button' onclick=Atpakal()>Atgriezties</button>";
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement