daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Sep 26th, 2016 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   //PDO
  3.   $mysql_host = 'localhost';
  4.   $port = '3306';
  5.   $username = 'root';
  6.   $password = '';
  7.   $database = 'blog';
  8.  
  9.   try {
  10.     $pdo = new PDO('mysql:host='.$mysql_host.';dbname='.$database.';port='.$port, $username, $password);
  11.     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12.  
  13.     if(!isset($_GET['id'])) {
  14.       $stmt = $pdo->query('SELECT wpisy.id, wpisy.tytul, wpisy.tresc, wpisy.data, uzytkownicy.nick FROM wpisy INNER JOIN uzytkownicy ON wpisy.id_autora = uzytkownicy.id');
  15.     } else {
  16.       $stmt = $pdo->query('SELECT wpisy.id, wpisy.tytul, wpisy.tresc, wpisy.data, uzytkownicy.nick FROM wpisy INNER JOIN uzytkownicy ON wpisy.id_autora = uzytkownicy.id WHERE wpisy.id_kategorii ='.$_GET["id"]);
  17.     }
  18.  
  19.     foreach($stmt as $row) {
  20.       echo "<div class='wpis'>";
  21.       echo "<div class='tytul'><a href=wpis.php?id=$row[id] class='tytul'>$row[tytul]</a><div class='data'>$row[data]</div></div>";
  22.       echo "<div class='tresc'>$row[tresc]</div>";
  23.       echo "<div class='autor'>$row[nick]</div>";
  24.       echo "</div>";
  25.     }
  26.  
  27.     $stmt->closeCursor();
  28.   } catch (PDOException $e) {
  29.     echo 'Błąd połączenia';
  30.   }
  31. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top