Advertisement
rozman50

Untitled

Oct 21st, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <style>
  5. table{
  6. border-collapse: collapse;
  7. }
  8. table, td, th {
  9. border: 1px solid black;
  10. font-size: 40px;
  11. }
  12.  
  13. </style>
  14. <?php
  15.  
  16. function drawArray($vrstica, $stolpec, $maxV, $maxS, $vrednost, $background, $caption){
  17.  
  18. if($vrstica == 0 && $stolpec == 0){
  19. echo "<table style='background-color:" . $background . ";'>";
  20. echo "<caption>" . $caption . "</caption>";
  21. }
  22.  
  23. if($stolpec == 0)
  24. echo "<tr>";
  25.  
  26. echo "<td style=' background-color:" . $background . "'>";
  27. echo $vrednost;
  28. echo "</td>";
  29.  
  30. if($stolpec == $maxS-1)
  31. echo "</tr>";
  32.  
  33. if($stolpec == $maxS-1 && $vrstica == $maxV-1)
  34. echo "</table>";
  35.  
  36. }
  37.  
  38. function compare($a, $b) {
  39. if ($a == $b) {
  40. return 0;
  41. }
  42. return ($a < $b) ? 1 : -1;
  43. }
  44.  
  45. function izpisSort($tab, $textPrviS, $textDrugiS){
  46. $i = 0;
  47. uasort($tab, 'compare');
  48. drawArray(0,0,13,2,$textPrviS,"red","");
  49. drawArray(0,1,13,2,$textDrugiS,"orange","");
  50. foreach($tab as $key=>$value){
  51. drawArray($i+1,0,13,2,$key,"red","");
  52. drawArray($i+1,1,13,2,$value,"orange","");
  53. $i++;
  54. }
  55. }
  56.  
  57. $temp1=array("jan"=>2.8, "feb"=>7.6, "mar"=>18.3, "apr"=>14.8, "maj"=>25.9,"jun"=>29.6,
  58. "jul"=>33.7,"aug"=>35.5, "sep"=>25.1, "okt"=>15.4, "nov"=>9.5, "dec"=>4.3);
  59.  
  60.  
  61. echo 'Prva tabela';
  62. izpisSort($temp1, "Mesec", "Temp");
  63.  
  64.  
  65. $temp2=array(
  66. "Ljubljana"=> array("jan"=>6.8, "feb"=>8.4, "mar"=>13.0, "apr"=>15.5, "maj"=>21.3,"jun"=>25.6,
  67. "jul"=>29.7,"aug"=>31.3, "sep"=>26.2, "okt"=>17.8, "nov"=>11.5, "dec"=>6.3),
  68. "Maribor"=> array("jan"=>2.8, "feb"=>7.6, "mar"=>18.3, "apr"=>14.8, "maj"=>25.9,"jun"=>29.6,
  69. "jul"=>33.7,"aug"=>35.5, "sep"=>25.1, "okt"=>15.4, "nov"=>9.5, "dec"=>4.3),
  70. "Koper"=> array("jan"=>6.8, "feb"=>9.6, "mar"=>13.4, "apr"=>17.0, "maj"=>24.6,"jun"=>31.6,
  71. "jul"=>34.7,"aug"=>35.3, "sep"=>26.2, "okt"=>14.2, "nov"=>9.0, "dec"=>3.1),
  72. "Piran"=> array("jan"=>5.7, "feb"=>6.6, "mar"=>9.6, "apr"=>12.3, "maj"=>22.9,"jun"=>26.5,
  73. "jul"=>32.2,"aug"=>31.1, "sep"=>25.1, "okt"=>20.4, "nov"=>16.5, "dec"=>10.3),
  74. "Ptuj"=> array("jan"=>4.8, "feb"=>6.9, "mar"=>12.7, "apr"=>16.3, "maj"=>22.4,"jun"=>27.1,
  75. "jul"=>31.4,"aug"=>32.8, "sep"=>24.3, "okt"=>18.4, "nov"=>12.5, "dec"=>2.3),
  76. "Kamnik"=> array("jan"=>3.8, "feb"=>5.9, "mar"=>13.5, "apr"=>17.2, "maj"=>23.3,"jun"=>26.3,
  77. "jul"=>30.5,"aug"=>32.1, "sep"=>24.6, "okt"=>17.1, "nov"=>11.2, "dec"=>5.5));
  78.  
  79. foreach($temp2 as $key=>$value)
  80. $november[$key] = $value['nov'];
  81.  
  82. // echo "<br>";
  83. // echo "Kraji od najhladnejsega do najtoplejsega, na osnovi podatkov za november." . "<br>";
  84. // echo "<br>";
  85.  
  86. echo 'druga tabela';
  87. izpisSort($november, "Kraj", "Temp");
  88.  
  89. foreach($temp2 as $key=>$value)
  90. $povp[$key] = array_sum($value)/count($value);
  91. //
  92. // echo "<br>";
  93. // echo "Kraji od najhladnejsega do najtoplejsega, na osnovi podatkov povprecne temperature." . "<br>";
  94. // echo "<br>";
  95.  
  96.  
  97. izpisSort($povp, "Kraj", "Povp temp");
  98. echo 'po tretji tabeli';
  99. ksort($povp);
  100.  
  101.  
  102. // echo "<br>";
  103. // echo "Kraji razvrsceni po abecedi." . "<br>";
  104. // echo "<br>";
  105.  
  106. izpisSort($povp, "Kraj po abecedi", "Povp temp");
  107. echo 'po četrti tabeli';
  108.  
  109. ?>
  110.  
  111. </body>
  112. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement