Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function show_blog_posts() {
- include('connection.php');
- $sql = "SELECT blog.title, blog.content, blog.posted_by, blog.date, article_comments.comments, article_comments.comment_by
- FROM blog LEFT OUTER JOIN article_comments
- ON blog.content_id = article_comments.comment_id
- WHERE blog.content != ''
- ORDER BY blog.content_id DESC";
- $result = mysqli_query($dbCon, $sql);
- while ($row = mysqli_fetch_array($result)) {
- echo
- "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" .
- "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" .
- "<article>" . $content = $row['content'] . "</article>" .
- "<div class='commented_by'>Posted by: " . $row['comment_by'] . "</div>" .
- "<div class='comments'>Comments: " . $row['comments'] . "</div>";
- }
- }
- function insert_comments($comment_by, $comments) {
- include('db_connection.php');
- $sql = "INSERT INTO article_comments (comments, comment_by) VALUES ('$comments', '$comment_by') WHERE article_comments.comment_id = blog.content_id";
- mysqli_query($dbCon, $sql);
- }
- function get_article_id($username) {
- include('db_connection.php');
- $username = sanitize($username);
- $sql = "SELECT content_id FROM `blog` WHERE content_id = '$content_id'";
- $query = mysqli_query($dbCon, $sql);
- return (mysqli_result($query, 0, 'content_id'));
- }
- function get_comment_id($comment_id) {
- include('db_connection.php');
- $comment_id = sanitize($username);
- $sql = "SELECT comment_id FROM `article_comments` WHERE comment_id = '$comment_id'";
- $query = mysqli_query($dbCon, $sql);
- return (mysqli_result($query, 0, 'comment_id'));
- }
- function show_blog_posts()
- {
- include('connection.php');
- $sql = "SELECT blog.title, blog.content, blog.content_id, blog.posted_by, blog.date
- FROM blog
- WHERE blog.content != ''
- ORDER BY blog.content_id DESC";
- $result = mysqli_query($dbCon, $sql);
- if (mysqli_num_rows($result) > 0) {
- while ($row = mysqli_fetch_array($result)) {
- echo
- "<h5 class='posted_by'>Posted by " . $posted_by = $row['posted_by'] . " on " . $row['date'] . "</h5>" .
- "<h1 class='content_headers'>" . $title = $row['title'] . "</h1>" .
- "<article>" . $content = $row['content'] . "</article>";
- $sql = "SELECT article_comments.comments, article_comments.comment_by
- FROM article_comments
- WHERE article_comments.content_id =" . $row['content_id'] . "
- ORDER BY article_comments.comment_id DESC";
- $comments = mysqli_query($dbCon, $sql);
- echo "<div>"; //comments panel
- if (mysqli_num_rows($result) > 0) {
- while ($comment = mysqli_fetch_array($comments)) {
- echo "<div class='commented_by'>Posted by: " . $comment['comment_by'] . "</div>";
- echo "<div class='comments'>Comments: " . $comment['comments'] . "</div>";
- }
- }
- echo "</div>"; //comments panel ends
- }
- }
- }
- function insert_comments($comment_by, $comments, $content_id) {
- include('db_connection.php');
- $sql = "INSERT INTO article_comments (content_id, comments, comment_by) VALUES ($content_id, '$comments', '$comment_by');";
- mysqli_query($dbCon, $sql);
- }
- function get_article_id($username) {
- include('db_connection.php');
- $username = sanitize($username);
- //if username is unique
- $sql = "SELECT content_id FROM `blog` WHERE username = '$username'";
- $query = mysqli_query($dbCon, $sql);
- return (mysqli_result($query, 0, 'content_id'));
- }
- function get_comment_id($username) {
- include('db_connection.php');
- $username = sanitize($username);
- $sql = "SELECT comment_id FROM `article_comments` WHERE username = '$username'";
- $query = mysqli_query($dbCon, $sql);
- return (mysqli_result($query, 0, 'comment_id'));
- }
Add Comment
Please, Sign In to add comment