sueckreimir

zupanijaMvc/index

Oct 9th, 2019 (edited)
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.27 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8.     <head>
  9.         <meta charset="UTF-8">
  10.         <title></title>
  11.     </head>
  12.     <body>
  13.         <?php
  14.        
  15.         class model
  16.         {
  17.             function pohranaPodataka()
  18.             {
  19.                 require 'konekcija.php';
  20.                 $abeceda=array('A','B','C','Č','Ć','D','Dž','E','F','G','H','I','J','K',
  21.                 'L','Lj','M','N','Nj','O','P','R','S','Š','T','U','V','Z','Ž');
  22.                
  23.                 if(isset($_GET['slovo']))
  24.                 {
  25.                     $slovo=$_GET['slovo'];
  26.                 }
  27.                 else
  28.                 {
  29.                     $slovo=NULL;
  30.                    
  31.                 }
  32.                
  33.                
  34.                 $query="select m.nazMjesto,z.nazZupanija,
  35.                sum(case when m.pbr=s.pbrRod then 1 else 0 end) as rodjenih,
  36.                sum(case when m.pbr=s.pbrStan then 1 else 0 end) as stanuju,
  37.                max(floor(datediff(now(),s.datRodStud)/365.25)) as najstariji,
  38.                min(floor(datediff(now(),s.datRodStud)/365.25)) as najmladji
  39.                from mjesto m
  40.                     left outer join zupanija z
  41.                     on m.sifZupanija=z.sifZupanija
  42.                     left outer join stud s
  43.                     on m.pbr=s.pbrRod or m.pbr=s.pbrStan
  44.                where m.nazMjesto like '$slovo%'    
  45.                group by m.nazMjesto,z.nazZupanija ";
  46.  
  47.                 $result= mysqli_query($link,$query);
  48.                 $numRows= mysqli_num_rows($result);
  49.                 while($row= mysqli_fetch_assoc($result))
  50.                 {
  51.                     $pod[]=array('nazMjesto'=>$row['nazMjesto'],
  52.                                'nazZupanija'=>$row['nazZupanija'],
  53.                                   'rodjenih'=>$row['rodjenih'],
  54.                                    'stanuju'=>$row['stanuju'],
  55.                                 'najstariji'=>$row['najstariji'],
  56.                                  'najmladji'=>$row['najmladji']);
  57.                 }
  58.                 if($numRows==0)
  59.                 {
  60.                     $pod=TRUE;
  61.                 }
  62.                
  63.                
  64.                 $x=0;
  65.                 $podaci=array('abeceda'=>$abeceda,
  66.                                 'slovo'=>$slovo,
  67.                                   'pod'=>$pod,
  68.                                     'x'=>$x,
  69.                               'numRows'=>$numRows);
  70.                 return $podaci;
  71.             }
  72.         }
  73.        
  74.         class view
  75.         {
  76.             function ispisPodataka($podaci)
  77.             {
  78.              
  79.                 echo '<a href="https://kresosusec.com.hr">'.'Početna'.'</a>'.'<br>';
  80.                
  81.                 foreach($podaci['abeceda'] as $key=>$val)
  82.                 {
  83.                     echo '<a href="index.php?slovo='.$val.'">'.$val.'</a>|';
  84.                 }
  85.                 if($podaci['slovo']==null)
  86.                 {
  87.                     echo '<br>'.'Odaberi neko slovo'.'<br>';
  88.                 }
  89.                 else
  90.                 {
  91.                     if($podaci['numRows']==0)
  92.                     {
  93.                         echo '<br>'.'Za birano slovo '.'<i><b>'.$podaci['slovo'].
  94.                         '</i></b>'.' nema nikakvih rezultata'.'<br>';
  95.                     }
  96.                     else
  97.                     {    
  98.                         echo '<table border="2">';
  99.                         echo '<tr><th>'.' '.'<th>'.
  100.                                          'Mjesto'.'<th>'.
  101.                                          'Županija'.'<th>'.
  102.                                          'Rođenih'.'<th>'.
  103.                                          'Stanuju'.'<th>'.
  104.                                          'Najmlađi'.'<th>'.
  105.                                          'Najstariji'.'<tr>';
  106.  
  107.                         foreach($podaci['pod'] as $key=>$val)
  108.                         {
  109.                             switch($val['najstariji'])
  110.                             {
  111.                                 case null:
  112.                                     $najstariji=0;
  113.                                     break;
  114.                                 default:
  115.                                     $najstariji=$val['najstariji'];
  116.                                     break;
  117.                             }
  118.                             switch($val['najmladji'])
  119.                             {
  120.                                 case null:
  121.                                     $najmladji=0;
  122.                                     break;
  123.                                 default :
  124.                                     $najmladji=$val['najmladji'];
  125.                                     break;
  126.                             }
  127.  
  128.                             $podaci['x']=$podaci['x']+1;
  129.  
  130.                             echo '<tr><td>'.$podaci['x'].'<td>'.
  131.                                                   $val['nazMjesto'].'<td>'.
  132.                                                   $val['nazZupanija'].'<td>'.
  133.                                                   $val['rodjenih'].'<td>'.
  134.                                                   $val['stanuju'].'<td>'.
  135.                                                   $najmladji.'<td>'.
  136.                                                   $najstariji.'<tr>';
  137.                         }
  138.                     }
  139.                     echo '</table>';
  140.                 }
  141.                
  142.                
  143.                
  144.                
  145.                
  146.             }
  147.            
  148.         }
  149.        
  150.         class controler
  151.         {
  152.             public $_Model;
  153.             public $_View;
  154.            
  155.             function __construct()
  156.             {
  157.                 $this->_Model=new model();
  158.                 $this->_View=new view();
  159.             }
  160.            
  161.             function start()
  162.             {
  163.                 $podaci= $this->_Model->pohranaPodataka();
  164.                 $this->_View->ispisPodataka($podaci);
  165.             }
  166.            
  167.         }
  168.        
  169.        
  170.         $pokreni=new controler();
  171.         $pokreni->start();
  172.        
  173.         ?>
  174.     </body>
  175. </html>
Add Comment
Please, Sign In to add comment