Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <html>
  2. <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!-- HTML Lapas kodejums-->
  3. <title> Nejauši skaitļi (PHP), Ikars Melnalksnis, 3DT-1 </title>
  4. <style>
  5.  
  6. body {
  7. background: LightBlue;
  8. font-size: 30px;
  9. }
  10. /*3 Limeņa virsraksta stils*/
  11. h3 {
  12. text-weight: bold;
  13. text-decoration: underline;
  14. }
  15. /*Teksta lauka stils */
  16. p {
  17. font-weight: bold;
  18. text-decoration: underline;
  19. }
  20. /*Tabulas stils*/
  21. table {
  22. border: 2px solid black;
  23. }
  24.  
  25. /*Tabulas sunu un rindu stils*/
  26. td,tr {
  27. border: 1px solid black;
  28. font-size: 20px;
  29. text-align: center;
  30. padding-left: 15px;
  31. padding-right: 15px;
  32. }
  33. button {
  34. margin-top: 15px;
  35. width: 100px;
  36. }
  37. </style>
  38. <script>
  39. function Atpakal() {
  40. window.history.back();
  41. }
  42. </script>
  43. <?php
  44. //Ciparu kopskaits ko iegūst no formas
  45. $ciklu_skaits = $_POST["skaitlu"];
  46.  
  47. //Ja nav iegūta vērtība, tad noklusētā ir 40
  48. if ($ciklu_skaits == 0) $ciklu_skaits = 40;
  49.  
  50. //Ciparu masivs
  51. $cipari = array();
  52.  
  53. //Izvades tabula
  54. $izvade = "<table>";
  55.  
  56. //For cikls kurs veiks ciklu_skaits ciklus
  57. for ($cikls = 0; $cikls < $ciklu_skaits; $cikls++) {
  58. //Masiva elements i iegūst nejaušu 1-100 vertibu
  59. $cipari[$cikls] = rand(1,100);
  60. }
  61.  
  62. //Pievieno izvades elementam masiva elementus
  63. foreach ($cipari as $cikls => $value) {
  64.  
  65. //Ja cikls skaitītājs ir dalāms ar 5
  66. if ($cikls % 5 == 0) {
  67. //Pievieno jaunu rindu ar pirmo sunu
  68. $izvade = $izvade . "</tr><tr><td>" . $value . "</td>";
  69. } else {
  70. //Savadak pievieno jaunu sunu
  71. $izvade = $izvade . "<td>" . $value . "</td>";
  72. }
  73. }
  74.  
  75. //Izvades tabulai pievieno tabulas beigu tagus
  76. $izvade = $izvade . "</tr></table>";
  77.  
  78. //Izvada tabulu
  79. echo "<h3>Gadījuma skaitļu ģenerēšana</h3><p>Atrastie ". $ciklu_skaits ." gadījuma skaitļi</p>". $izvade;
  80. echo "<button type='button' onclick=Atpakal()>Atgriezties</button>";
  81. ?>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement