Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <?php
- class model
- {
- function pohranaPodataka()
- {
- require 'konekcija.php';
- $abeceda=array('A','B','C','Č','Ć','D','Dž','E','F','G','H','I','J','K',
- 'L','Lj','M','N','Nj','O','P','R','S','Š','T','U','V','Z','Ž');
- if(isset($_GET['slovo']))
- {
- $slovo=$_GET['slovo'];
- }
- else
- {
- $slovo=NULL;
- }
- $query="select m.nazMjesto,z.nazZupanija,
- sum(case when m.pbr=s.pbrRod then 1 else 0 end) as rodjenih,
- sum(case when m.pbr=s.pbrStan then 1 else 0 end) as stanuju,
- max(floor(datediff(now(),s.datRodStud)/365.25)) as najstariji,
- min(floor(datediff(now(),s.datRodStud)/365.25)) as najmladji
- from mjesto m
- left outer join zupanija z
- on m.sifZupanija=z.sifZupanija
- left outer join stud s
- on m.pbr=s.pbrRod or m.pbr=s.pbrStan
- where m.nazMjesto like '$slovo%'
- group by m.nazMjesto,z.nazZupanija ";
- $result= mysqli_query($link,$query);
- $numRows= mysqli_num_rows($result);
- while($row= mysqli_fetch_assoc($result))
- {
- $pod[]=array('nazMjesto'=>$row['nazMjesto'],
- 'nazZupanija'=>$row['nazZupanija'],
- 'rodjenih'=>$row['rodjenih'],
- 'stanuju'=>$row['stanuju'],
- 'najstariji'=>$row['najstariji'],
- 'najmladji'=>$row['najmladji']);
- }
- if($numRows==0)
- {
- $pod=TRUE;
- }
- $x=0;
- $podaci=array('abeceda'=>$abeceda,
- 'slovo'=>$slovo,
- 'pod'=>$pod,
- 'x'=>$x,
- 'numRows'=>$numRows);
- return $podaci;
- }
- }
- class view
- {
- function ispisPodataka($podaci)
- {
- echo '<a href="https://kresosusec.com.hr">'.'Početna'.'</a>'.'<br>';
- foreach($podaci['abeceda'] as $key=>$val)
- {
- echo '<a href="index.php?slovo='.$val.'">'.$val.'</a>|';
- }
- if($podaci['slovo']==null)
- {
- echo '<br>'.'Odaberi neko slovo'.'<br>';
- }
- else
- {
- if($podaci['numRows']==0)
- {
- echo '<br>'.'Za birano slovo '.'<i><b>'.$podaci['slovo'].
- '</i></b>'.' nema nikakvih rezultata'.'<br>';
- }
- else
- {
- echo '<table border="2">';
- echo '<tr><th>'.' '.'<th>'.
- 'Mjesto'.'<th>'.
- 'Županija'.'<th>'.
- 'Rođenih'.'<th>'.
- 'Stanuju'.'<th>'.
- 'Najmlađi'.'<th>'.
- 'Najstariji'.'<tr>';
- foreach($podaci['pod'] as $key=>$val)
- {
- switch($val['najstariji'])
- {
- case null:
- $najstariji=0;
- break;
- default:
- $najstariji=$val['najstariji'];
- break;
- }
- switch($val['najmladji'])
- {
- case null:
- $najmladji=0;
- break;
- default :
- $najmladji=$val['najmladji'];
- break;
- }
- $podaci['x']=$podaci['x']+1;
- echo '<tr><td>'.$podaci['x'].'<td>'.
- $val['nazMjesto'].'<td>'.
- $val['nazZupanija'].'<td>'.
- $val['rodjenih'].'<td>'.
- $val['stanuju'].'<td>'.
- $najmladji.'<td>'.
- $najstariji.'<tr>';
- }
- }
- echo '</table>';
- }
- }
- }
- class controler
- {
- public $_Model;
- public $_View;
- function __construct()
- {
- $this->_Model=new model();
- $this->_View=new view();
- }
- function start()
- {
- $podaci= $this->_Model->pohranaPodataka();
- $this->_View->ispisPodataka($podaci);
- }
- }
- $pokreni=new controler();
- $pokreni->start();
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment