Guest User

Untitled

a guest
Oct 23rd, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. Administracija.php:
  2. <?php
  3. include ("Database.php");
  4. $objekat = new Database("bazanovosti");
  5. ?>
  6. <html>
  7. <head>
  8. </head>
  9. <body>
  10. <h1>Rad sa bazom</h1>
  11. <ul>
  12. <li><a href="Administracija.php?strana=prikazi">Prikazi</a></li>
  13. <li><a href="Administracija.php?strana=ubaci">Ubaci</a></li>
  14. <li><a href="Administracija.php?strana=izmeni">Izmeni</a></li>
  15. <li><a href="Administracija.php?strana=obrisi">Obrisi</a></li>
  16. </ul>
  17. <?php
  18. if (isset($_GET["strana"])){
  19. $strana = $_GET["strana"];
  20. } else {
  21. $strana = "prikazi";
  22. }
  23. switch($strana){
  24. case "prikazi":
  25. {
  26. $objekat->select();
  27. ?>
  28. <table><tr>
  29. <td>Naslov</td>
  30. <td>Tekst</td>
  31. </tr>
  32. <?php
  33. while($red=$objekat->getResult()->fetch_object()){
  34. ?>
  35. <tr>
  36. <td><?php echo $red->naslov; ?></td>
  37. <td><?php echo $red->tekst; ?></td>
  38. </tr>
  39. <?php
  40. }
  41. echo "</table>";
  42. }
  43. break;
  44. case "ubaci":
  45. {
  46.  
  47. }
  48. break;
  49. case "izmeni":
  50. {
  51.  
  52. }
  53. break;
  54. case "obrisi":
  55. {
  56. }
  57. break;
  58. default:
  59. echo "Gre�ka 404: Stranica nije pronadena!";
  60. break;
  61.  
  62. }
  63. ?>
  64. </body>
  65. </html>
  66.  
  67. Database.php:
  68. <?php
  69. class Database{
  70.  
  71. private $hostname = "localhost";
  72. private $username = "root";
  73. private $password = '';
  74. private $dbname;
  75. private $dblink;
  76. private $result;
  77.  
  78. function __construct($imeBaze){
  79. $this->dbname = $imeBaze;
  80. $this->connect();
  81. }
  82.  
  83. function getResult(){
  84. return $this->result;
  85. }
  86.  
  87. function connect(){
  88. $this->dblink = new mysqli($this->hostname, $this->username, $this->password, $this->dbname);
  89. }
  90.  
  91. function select($columns = "*", $table = "novosti"){
  92. $upit = "SELECT " . $columns . " from " . $table;
  93. $this->executeQuery($upit);
  94. }
  95.  
  96. function executeQuery($upit){
  97. $this->result = $this->dblink->query($upit);
  98. return true;
  99. }
  100.  
  101. }
  102.  
  103. ?>
Add Comment
Please, Sign In to add comment