Guest User

Untitled

a guest
Jan 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. class CommentsManager
  2. {
  3.     const USER = 'root';
  4.     const PASS = '';
  5.     const DATABASE = 'colina';
  6.     const SERVER = 'localhost';
  7.    
  8.     private $_conection;
  9.  
  10.     private static function connect()
  11.     {
  12.         $this->_conection = mysql_connect(
  13.             self::SERVER,
  14.             self::USER,
  15.             self::PASS
  16.         );
  17.        
  18.         mysql_select_db(
  19.             self::DATABASE,
  20.             $this->_conection
  21.         );
  22.     }
  23.    
  24.     private static function disconnect()
  25.     {
  26.         mysql_close($this->_conection);
  27.     }
  28.    
  29.     private static function getComments($sql)
  30.     {
  31.         self::connect();
  32.         $result = mysql_query($sql, $this->_conection);
  33.        
  34.         while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  35.             $all[] = $row;
  36.         }
  37.         self::disconnect();
  38.         return $all;
  39.     }
  40.    
  41.     public static function buildComments()
  42.     {
  43.         $t = Template::getInstance();
  44.         $t->set_block( '_COMENTARIOS', '_BLK_COMMENTS','TPL_COMMENTS_ITEMS' );
  45.         $sql = "SELECT nombre_visita,fecha_visita,comentario_visita FROM 'visitas'";
  46.         foreach (self::getComments($sql) as $item) {
  47.             $t->set_var("TPL_COMMENT_NAME", $item['nombre_visita']);
  48.             $t->set_var("TPL_COMMENT_DATE", $item['fecha_visita']);
  49.             $t->set_var("TPL_COMMENT_BODY", $item['comentario_visita']);
  50.             $t->parse( 'TPL_COMMENTS_ITEMS', '_BLK_COMMENTS', 1) ;
  51.         }
  52.         $t->parse('TPL_COMMENTS','_COMENTARIOS');
  53.     }
  54. }
Add Comment
Please, Sign In to add comment