Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2. class News
  3. {
  4.     public static function getNewsItemById($id)
  5.     {
  6.        
  7.        
  8.     }
  9.    
  10.     public static function getNewsList()
  11.     {
  12.          $host = 'localhost';
  13.         $dbname = 'mvc_site';
  14.         $user = 'root';
  15.         $password = '';
  16.         $db = new PDO("mysql:host = $host; dbname = $dbname", $user, $password);
  17.        
  18.         $newList = array();
  19.        
  20.         $result = $db->query('SELECT id, title, date, short_content'
  21.                              .'FROM news'
  22.                              .'RODER BY date DESC'
  23.                              .'LIMIT 10');
  24.        
  25.         $i = 0;
  26.         while($row = $result->fetch()) {
  27.            $newList[$i]['id'] =  $row['id'];
  28.            $newList[$i]['title'] =  $row['title'];
  29.            $newList[$i]['date'] =  $row['date'];
  30.            $newList[$i]['short_content'] =  $row['short_content'];
  31.            $i++;
  32.         }
  33.        
  34.         return $newList;
  35.     }
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement