Advertisement
Guest User

Xing's Blog - Includes.php

a guest
Dec 9th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php  
  2. include 'BlogPost.php';
  3.  
  4. $connection = mysql_connect('mysql11.000webhost.com', 'a5273704_MtXing', 'MyBlog1') or die ("<img src='/Error.png' alt='ERROR'/><h1 class='Error'>BIG SCARY ERROR, GO!</h1><p class='Error'>Yeah... Whoops. Something went wrong when logging into the database. Sorry about that.</p>");  
  5. $database = "a5273704_Blog";  
  6. mysql_select_db($database, $connection) or die ("<img src='/Error.png' alt='ERROR'/><h1 class='Error'>BIG SCARY ERROR, GO!</h1><p class='Error'>Yeah... Whoops. Something went wrong when loading the database. Sorry about that.</p>");  
  7.  
  8. function GetBlogPosts($inId =null, $inTagId =null)  
  9. {  
  10.     if (!empty($inId)){  
  11.         $query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC");  
  12.     }  
  13.     else if (!empty($inTagId)){  
  14.         $query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");  
  15.     } else{  
  16.         $query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");  
  17.     }  
  18.    
  19.     $postArray = array();  
  20.     while ($row = mysql_fetch_assoc($query)){  
  21.         $myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_posted']);  
  22.         array_push($postArray, $myPost);  
  23.     }  
  24.     return $postArray;
  25. }  
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement