Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Administracija.php:
- <?php
- include ("Database.php");
- $objekat = new Database("bazanovosti");
- ?>
- <html>
- <head>
- </head>
- <body>
- <h1>Rad sa bazom</h1>
- <ul>
- <li><a href="Administracija.php?strana=prikazi">Prikazi</a></li>
- <li><a href="Administracija.php?strana=ubaci">Ubaci</a></li>
- <li><a href="Administracija.php?strana=izmeni">Izmeni</a></li>
- <li><a href="Administracija.php?strana=obrisi">Obrisi</a></li>
- </ul>
- <?php
- if (isset($_GET["strana"])){
- $strana = $_GET["strana"];
- } else {
- $strana = "prikazi";
- }
- switch($strana){
- case "prikazi":
- {
- $objekat->select();
- ?>
- <table><tr>
- <td>Naslov</td>
- <td>Tekst</td>
- </tr>
- <?php
- while($red=$objekat->getResult()->fetch_object()){
- ?>
- <tr>
- <td><?php echo $red->naslov; ?></td>
- <td><?php echo $red->tekst; ?></td>
- </tr>
- <?php
- }
- echo "</table>";
- }
- break;
- case "ubaci":
- {
- }
- break;
- case "izmeni":
- {
- }
- break;
- case "obrisi":
- {
- }
- break;
- default:
- echo "Gre�ka 404: Stranica nije pronadena!";
- break;
- }
- ?>
- </body>
- </html>
- Database.php:
- <?php
- class Database{
- private $hostname = "localhost";
- private $username = "root";
- private $password = '';
- private $dbname;
- private $dblink;
- private $result;
- function __construct($imeBaze){
- $this->dbname = $imeBaze;
- $this->connect();
- }
- function getResult(){
- return $this->result;
- }
- function connect(){
- $this->dblink = new mysqli($this->hostname, $this->username, $this->password, $this->dbname);
- }
- function select($columns = "*", $table = "novosti"){
- $upit = "SELECT " . $columns . " from " . $table;
- $this->executeQuery($upit);
- }
- function executeQuery($upit){
- $this->result = $this->dblink->query($upit);
- return true;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment