Guest User

Untitled

a guest
Jul 15th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. function show_blog_posts() {
  2. include('connection.php');
  3. $sql = "SELECT blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by
  4. FROM blog LEFT OUTER JOIN article_comments
  5. ON blog.content_id = article_comments.comment_id
  6. WHERE blog.content != ''
  7. ORDER BY blog.content_id DESC";
  8. $result = mysqli_query($dbCon, $sql);
  9. while ($row = mysqli_fetch_array($result)) {
  10. echo
  11. "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" .
  12. "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" .
  13. "<article>" . $content = $row['content'] . "</article>" .
  14. "<div class='commented_by'>Posted by: " . $row['comment_by'] . "</div>" .
  15. "<div class='comments'>Comments: " . $row['comments'] . "</div>";
  16. }
  17. }
  18.  
  19. function insert_comments($comment_by, $comments) {
  20. include('db_connection.php');
  21. $sql = "INSERT INTO article_comments (comments, comment_by) VALUES ('$comments', '$comment_by') WHERE article_comments.comment_id = blog.content_id";
  22. mysqli_query($dbCon, $sql);
  23. }
  24.  
  25. function get_article_id($username) {
  26. include('db_connection.php');
  27. $username = sanitize($username);
  28. $sql = "SELECT content_id FROM `blog` WHERE content_id = '$content_id'";
  29. $query = mysqli_query($dbCon, $sql);
  30. return (mysqli_result($query, 0, 'content_id'));
  31. }
  32.  
  33. function get_comment_id($comment_id) {
  34. include('db_connection.php');
  35. $comment_id = sanitize($username);
  36. $sql = "SELECT comment_id FROM `article_comments` WHERE comment_id = '$comment_id'";
  37. $query = mysqli_query($dbCon, $sql);
  38. return (mysqli_result($query, 0, 'comment_id'));
  39. }
  40.  
  41. function show_blog_posts()
  42. {
  43. include('connection.php');
  44. $sql = "SELECT blog.title, blog.content, blog.content_id, blog.posted_by, blog.date
  45. FROM blog
  46. WHERE blog.content != ''
  47. ORDER BY blog.content_id DESC";
  48. $result = mysqli_query($dbCon, $sql);
  49.  
  50. if (mysqli_num_rows($result) > 0) {
  51. while ($row = mysqli_fetch_array($result)) {
  52. echo
  53. "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" .
  54. "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" .
  55. "<article>" . $content = $row['content'] . "</article>";
  56.  
  57. $sql = "SELECT article_comments.comments, article_comments.comment_by
  58. FROM article_comments
  59. WHERE article_comments.content_id =" . $row['content_id'] . "
  60. ORDER BY article_comments.comment_id DESC";
  61. $comments = mysqli_query($dbCon, $sql);
  62.  
  63. echo "<div>"; //comments panel
  64. if (mysqli_num_rows($result) > 0) {
  65. while ($comment = mysqli_fetch_array($comments)) {
  66. echo "<div class='commented_by'>Posted by: " . $comment['comment_by'] . "</div>";
  67. echo "<div class='comments'>Comments: " . $comment['comments'] . "</div>";
  68. }
  69. }
  70. echo "</div>"; //comments panel ends
  71. }
  72. }
  73.  
  74. }
  75.  
  76. function insert_comments($comment_by, $comments, $content_id) {
  77. include('db_connection.php');
  78. $sql = "INSERT INTO article_comments (content_id, comments, comment_by) VALUES ($content_id, '$comments', '$comment_by');";
  79. mysqli_query($dbCon, $sql);
  80. }
  81.  
  82. function get_article_id($username) {
  83. include('db_connection.php');
  84. $username = sanitize($username);
  85. //if username is unique
  86. $sql = "SELECT content_id FROM `blog` WHERE username = '$username'";
  87. $query = mysqli_query($dbCon, $sql);
  88. return (mysqli_result($query, 0, 'content_id'));
  89. }
  90.  
  91. function get_comment_id($username) {
  92. include('db_connection.php');
  93. $username = sanitize($username);
  94. $sql = "SELECT comment_id FROM `article_comments` WHERE username = '$username'";
  95. $query = mysqli_query($dbCon, $sql);
  96. return (mysqli_result($query, 0, 'comment_id'));
  97. }
Add Comment
Please, Sign In to add comment