Advertisement
sueckreimir

prosjekMVC/index

Oct 10th, 2019 (edited)
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.58 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.                 if(isset($_GET['broj']))
  21.                 {
  22.                     $broj=$_GET['broj'];
  23.                     $pocetno=($broj-1)*15;
  24.                     $y=($broj-1)*15;
  25.                 }
  26.                 else
  27.                 {
  28.                     $broj=1;
  29.                     $pocetno=0;
  30.                     $y=0;
  31.                 }
  32.                 $query="select u.mbrStud,u.imeStud,u.prezStud,
  33.                round(avg(o.ocjena),2) as prosjek
  34.                from ucenici u
  35.                left outer join ocjene o
  36.                on u.mbrStud=o.mbrStud
  37.                group by u.mbrStud
  38.                limit $pocetno,15";
  39.                 $result=mysqli_query($link,$query);
  40.                
  41.                 while($row=mysqli_fetch_assoc($result))
  42.                 {
  43.                     $pod[]=array('mbrStud'=>$row['mbrStud'],
  44.                                  'imeStud'=>$row['imeStud'],
  45.                                 'prezStud'=>$row['prezStud'],
  46.                                  'prosjek'=>$row['prosjek']);
  47.                                    
  48.                 }
  49.                
  50.                 $query2="select mbrStud from ucenici";
  51.                 $result2=mysqli_query($link,$query2);
  52.                 $numRows=mysqli_num_rows($result2);
  53.                 $total=ceil($numRows/15);
  54.                 $x=0;
  55.                 $p=array('pod'=>$pod,
  56.                            'y'=>$y,
  57.                        'total'=>$total,
  58.                         'broj'=>$broj);
  59.                
  60.                 return $p;
  61.             }
  62.            
  63.         }
  64.        
  65.         class view
  66.         {
  67.             function ispisPodataka($p)
  68.             {
  69.                 echo '<center>';
  70.                 echo '<a href="https://kresosusec.com.hr">'.'Početna'.'</a>'.'<br>';
  71.                 echo '<table border="2">';
  72.                 echo '<tr><th>'.''.'<th>'.
  73.                              'MBR'.'<th>'.
  74.                              'Ime'.'<th>'.
  75.                          'Prezime'.'<th>'.
  76.                          'Prosjek'.'<tr>';
  77.                      
  78.                 foreach($p['pod'] as $key=>$val)
  79.                 {
  80.                     $p['y']=$p['y']+1;
  81.                     $mbr='<a href="predmeti.php?mbr='.$val['mbrStud'].'&prosjek='.$val['prosjek'].'">'.$val['prosjek'].'</a>';
  82.                    
  83.                     echo '<tr><td>'.$p['y'].'<td>'.
  84.                                     $val['mbrStud'].'<td>'.
  85.                                     $val['imeStud'].'<td>'.
  86.                                     $val['prezStud'].'<td>'.
  87.                                     $mbr.'<tr>';
  88.                 }
  89.                 echo '</table>';
  90.                
  91.                 if($p['broj']<$p['total'])
  92.                 {
  93.                     echo '<a href="index.php?broj='.($p['broj']+1).'">'.'Naprijed'.'</a>'.'<br>';
  94.                 }
  95.                 else
  96.                 {
  97.                     echo '<a href="index.php">'.'Naprijed'.'</a>'.'<br>';
  98.                 }
  99.                
  100.                 for($x=1;$x<=$p['total'];$x=$x+1)
  101.                 {
  102.                     echo '<a href="index.php?broj='.$x.'">'.$x.'</a>|';
  103.                 }
  104.                
  105.                 if($p['broj']>1)
  106.                 {
  107.                     echo '<br>'.'<a href="index.php?broj='.($p['broj']-1).'">'.'Natrag'.'</a>';
  108.                 }
  109.                 else
  110.                 {
  111.                     echo '<br>'.'<a href="index.php">'.'Natrag'.'</a>';
  112.                 }
  113.                
  114.                
  115.                
  116.             }
  117.         }
  118.        
  119.         class controler
  120.         {
  121.             public $_Model;
  122.             public $_View;
  123.            
  124.             function __construct()
  125.             {
  126.                 $this->_Model=new model;
  127.                 $this->_View=new view();
  128.                
  129.             }
  130.            
  131.             function start()
  132.             {
  133.                 $p= $this->_Model->pohranaPodataka();
  134.                 $this->_View->ispisPodataka($p);
  135.             }
  136.        
  137.         }
  138.        
  139.        
  140.         $pokreni=new controler();
  141.         $pokreni->start();
  142.        
  143.         ?>
  144.     </body>
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement