static function dajKolegijeProfesora($id) { $sql = "SELECT * FROM kolegij LEFT JOIN kolegij_osoblje ON k_fk = k_id LEFT JOIN osoblje ON o_id = o_fk WHERE o_id = {$id}"; $baza = new BazaNastavnici(); $kolegiji = $baza->query($sql); $brojac = 0; $kolegijiDinstinct = array(); if ($kolegiji->num_rows > 0) { while ($row = $kolegiji->fetch_assoc()) { $naziv = $row["k_naziv"]; if (!in_array($naziv, $kolegijiDinstinct)) { $kolegijiDinstinct[$brojac++] = $naziv; } } } return $kolegijiDinstinct; }
public function connect() { // Try and connect to the database if (!isset(self::$connection)) { self::$connection = new mysqli(self::$host, self::$username, self::$password, self::$database); self::$connection->set_charset('utf8'); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. echo 'Cannot connect to database.'; return false; } return self::$connection; }