Advertisement
Underworld1337

Untitled

Oct 12th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2. class news
  3. {
  4.     /**
  5.       * /do_img/global/events/
  6.       * /do_img/global/events/icons/
  7.       */
  8.     private $con;
  9.     private $data;
  10.     private $cnt;
  11.  
  12.     public function __construct() {
  13.         $this->con = $GLOBALS['DB'];
  14.     }
  15.  
  16.     public function init(){
  17.         $qry = $this->con->prepare("SELECT * FROM news ORDER BY nID DESC LIMIT 7");
  18.         if ($qry->execute()){
  19.             if ($qry->rowCount() != 0){
  20.                 $this->cnt = $qry->rowCount();
  21.                 $arr = $qry->fetchAll(PDO::FETCH_ASSOC);
  22.                 $this->data = array_combine(range(1, count($arr)), array_values($arr));
  23.                 return TRUE;
  24.             }else
  25.                 return FALSE;
  26.         }else
  27.             return FALSE;
  28.     }
  29.    
  30.     public function get($type){
  31.         $ret = "";
  32.         for($i=1;$i<=$this->cnt;$i++){
  33.             if($type == "icons"){
  34.                 $spc = ($i != 1) ? "style=\"margin-left: 6px;\"" : "";
  35.                 $ret .= "<img id=\"newsIcon_" . $this->data[$i]['newsID'] . "\" class=\"breakingNewsIcon\" src=\"./do_img/global/events/icons/" . $this->data[$i]['icon'] . "\" width=\"21\" height=\"21\" " . $spc . ">";
  36.             }elseif($type == "news"){
  37.                 $spc = ($i != 1) ? "style=\"display: none;\"" : "";
  38.                 $ret .= "<div id=\"newsText_" . $this->data[$i]['newsID'] . "\" class=\"newsTextContainer\" " . $spc . "><h3>" . $this->data[$i]['headline'] . "</h3>" . $this->data[$i]['text'] . "</div>";
  39.             }elseif($type == "images"){
  40.                 $spc = ($i != 1) ? "style=\"display: none;\"" : "style=\"display: block;\"";
  41.                 $ret .= "<img id=\"newsImage_" . $this->data[$i]['newsID'] . "\" src=\"./do_img/global/events/" . $this->data[$i]['image'] . "\" class=\"newsImage oldNews\" " . $spc . ">";
  42.             }elseif($type == "jsarray"){
  43.                 $ret .= "newsItemIds.push('" . $this->data[$i]['newsID'] . "');";
  44.             }elseif($type == "jsarray2"){
  45.                 $ret .= "uploadedNewsIds.push('" . $this->data[1]['newsID'] . "');";
  46.                 break;
  47.             }
  48.         }
  49.         return $ret;
  50.     }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement