Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.81 KB | None | 0 0
  1. <?php
  2. error_reporting();
  3. session_start();
  4.  
  5. $MYSQL_HOST = 'localhost';
  6. $MYSQL_DB = 'eatt';
  7. $MYSQL_PASSWORD = '';
  8. $MYSQL_USER = 'root';
  9.  
  10. try
  11. {
  12.      $connection = new PDO("mysql:host={$MYSQL_HOST};dbname={$MYSQL_DB}",$MYSQL_USER,$MYSQL_PASSWORD);
  13.      $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14.     }catch(PDOException $e)
  15.     {
  16.         echo $e->getMessage();
  17.     }
  18.    
  19. class TrashCodeXD
  20. {
  21.         protected $db;
  22.         public function __construct($connection)
  23.         {
  24.             $this->db = $connection;
  25.         }
  26.    
  27.    
  28.     public function WhatsThis()
  29.     {
  30.         $SQL = $this->db->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM posts");
  31.         $SQL->execute();
  32.  
  33.         $result = $this->db->prepare("SELECT FOUND_ROWS()");
  34.         $result->execute();
  35.         $rows = $result->fetchColumn();
  36.         if($SQL->rowCount() > 20)
  37.         {
  38.             $rows = $SQL->fetch(PDO::FETCH_ASSOC);
  39.             $_SESSION['post'] = $rows;
  40.             $r1 = rand(1, $rows);
  41.             $r2 = rand(1, $rows);
  42.             $r3= rand(1, $rows);
  43.             $r4 = rand(1, $rows);
  44.             $r5 = rand(1, $rows);
  45.             $r6 = rand(1, $rows);
  46.             $r7 = rand(1, $rows);
  47.             $r8 = rand(1, $rows);
  48.             $r9 = rand(1, $rows);
  49.             $r10 = rand(1, $rows);
  50.             $r11 = rand(1, $rows);
  51.             $myarray = array($r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8, $r9, $r10, $r11);
  52.            
  53.             while($array_counter < 10)
  54.             {
  55.                 $theid = $myarray[$array_counter];
  56.                 $SQL = $this->db->prepare("SELECT * FROM posts WHERE id = :id");
  57.                 $SQL->bindParam(":id",$theid);
  58.                 $result = $SQL->execute();
  59.                 $pst_row = $SQL->fetch(PDO::FETCH_ASSOC);
  60.                 if($result)
  61.                 {
  62.                     $_SESSION['user_data']['post'] = $pst_row;
  63.                     $string .= "<div id='post'>".$_SESSION['user_data']['post']['person']."<div>".$_SESSION['user_data']['post']['content']."</div><div id='base'><span class='mark'>Mark</span><span class='comment'>Comment</span><span class='views'>Views</span>".$_SESSION['user_data']['post']['date']."</div></div>";
  64.                     var_dump($string);
  65.                     echo 'checking....';
  66.                 }else{
  67.                     echo "<br /> An error has occured";
  68.                 }
  69.                 $array_counter++;
  70.             }
  71.             echo $string;
  72.         }else{
  73.             $r1 = rand(1, $rows);
  74.             $SQL = $this->db->prepare("SELECT * FROM posts WHERE id = :id");
  75.             $SQL->bindParam(":id",$r1);
  76.             $result = $SQL->execute();
  77.             $pst_row = $SQL->fetch(PDO::FETCH_ASSOC);
  78.             if($result)
  79.             {
  80.                 $_SESSION['user_data']['post'] = $pst_row;
  81.                 $string = "<div id='post'>".$_SESSION['user_data']['post']['person']."<div>".$_SESSION['user_data']['post']['content']."</div><div id='base'><span class='mark'>Mark</span><span class='comment'>Comment</span><span class='views'>Views</span>".$_SESSION['user_data']['post']['date']."</div></div>";
  82.                 echo '<pre align="left" style="text-indent:10px; color:#fff;"></pre>';
  83.                 echo $string;
  84.             }else{
  85.                 echo "<br /> An error has occured";
  86.             }
  87.         }
  88.     }
  89. }
  90. $object = new TrashCodeXD($connection);
  91. $object->WhatsThis()
  92.                
  93.        
  94.            
  95.    
  96.    
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement