Advertisement
Guest User

Xing's Blog - BlogPost.php

a guest
Dec 9th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2. class BlogPost{
  3.    
  4.     public $id;
  5.     public $title;
  6.     public $post;
  7.     public $tags;
  8.     public $datePosted;
  9.    
  10.     function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null){
  11.         $this->id = $inId;
  12.         $this->title = $inTitle;
  13.         $this->post = $inPost;
  14.        
  15.         $splitDate = explode("-", $inDatePosted);
  16.         $this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];
  17.        
  18.         $query = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);
  19.         $row = mysql_fetch_assoc($query);
  20.         $this->author = $row["first_name"] . " " . $row["last_name"];
  21.        
  22.         $query = mysql_query("SELECT * F ROMblog_post_tags WHERE blog_post_tags.blog_post_id = " . $inId);
  23.        
  24.         $query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
  25.        
  26.         $postTags = "No Tags";
  27.         $tagArray = array();
  28.         $tagIDArray = array();
  29.         while($row = mysql_fetch_assoc($query)){
  30.             array_push($tagArray, $row["name"]);  
  31.             array_push($tagIDArray, $row["id"]);  
  32.         }
  33.        
  34.         if (sizeof($tagArray) > 0){  
  35.             foreach ($tagArray as $tag){  
  36.                 if ($postTags == "No Tags"){  
  37.                     $postTags = $tag;  
  38.                 } else{  
  39.                     $postTags = $postTags . ", " . $tag;  
  40.                 }  
  41.             }  
  42.         }  
  43.         $this->tags = $postTags;
  44.        
  45.        
  46.     }
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement