Created
April 27, 2019 21:25
-
-
Save DecodeWorms/98383ac1f0841a5638ee300b6e400abe to your computer and use it in GitHub Desktop.
the blogger description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once"databaseConnector.php"; | |
require_once"custom.php"; | |
//the bootsrap design below is for heading | |
echo<<<___END | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="../assets/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | |
<link rel="stylesheet" type="text/css" href="../assets/css/practices.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> | |
<script src="../assets/js/boostrap.min.js"></script> | |
<body> | |
<nav class="navbar fixed-top navbar-expand-lg bg-danger"> | |
<a class="navbar-brand text-white" href="#">BRAND</a> | |
<a href="" class="nav-link text-white">HOME</a> | |
<a href="" class="nav-link text-white">UPLOAD BLOGS</a> | |
<a href="" class="nav-link text-white float-right">SIGN OUT</a> | |
</nav> | |
</body> | |
</html> | |
___END; | |
function fetchBlogs(){ | |
session_start(); | |
//the sql query fetches the informations for each blog the user posted so the while loop fetch them out | |
$postId = ""; | |
$query = "SELECT*FROM blogger"; | |
$result = mysql_query($query); | |
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ | |
//this codes fetch number of comments for each post so i used post_id to tracked it | |
$postId = $row[id]; | |
$idQuery = "SELECT post_id FROM comments | |
WHERE post_id = '$postId'"; | |
$idResult = mysql_query($idQuery); | |
$idResult2 = mysql_num_rows($idResult); | |
echo<<<___END | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="../assets/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> | |
<link rel="stylesheet" type="text/css" href="../assets/css/practices.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> | |
<script src="../assets/js/boostrap.min.js"></script> | |
<body> | |
<div class="container"> | |
<div class="card mt-3" style="width: 500px;" id="displayCard"> | |
<div class="card-header bg-secondary text-white"> | |
<img src="$row[user_Image]" style="width: 50px; height:50px;" class="img-circle ml-1 mt-3"><span class="ml-3" ><b>$row[user_id]</b></span> | |
</div> | |
<div class="card-body"> | |
<img src="$row[image]" style="width: 480px"> | |
<div class="card-title mt-2"><p><b>$row[user_id]</b> $row[description]</p></div> | |
<button type = "" class = "btn btn-light mb-2" data-toggle = "modal" data-target = "#comments">$idResult2 comments..</button> | |
<form action="display_blog.php" method="post"> | |
<input type="hidden" class="form-control" placeholder="" name="idNumber" value="$postId"> | |
<input type="text" class="form-control" placeholder="Add comment" name="comments"> | |
<button class="btn btn-secondary mt-1">post</button> | |
</form> | |
</div> | |
___END; | |
//THE CODE BELOW ,THIS IS WHERE THE PROBLEM IS...I WANT COMMENTS FOR EACH POST,I ACTUALLY ACHIEVED THIS BUT THE RESULTS OF THE QUERY IS NOT SHOWING ALL THE RESUYLTS INSIDE THE HTML DESIGNED FOR IT BUT SHOWED ALL THE RESULTS OUTSIDE THE HTML THAT ARE NOT DESIGNED FOR IT | |
$infoQuery = "SELECT*FROM comments | |
WHERE post_id = '$postId'"; | |
$infoResult = mysql_query($infoQuery); | |
//THIS IS ANOTHER WHILE LOOP INSIDE THE FIRST WHILE LOOP | |
while ($infoRow = mysql_fetch_array($infoResult,MYSQL_ASSOC)){ | |
echo<<<___END | |
<div class = "modal fade" id = "comments" tabindex = "-1" role = "dialog" aria-labelledby = "commentslabel" aria-hidden = "true"> | |
<div class = "modal-dialog modal-dialog-centered" role = "document"> | |
<div class = "modal-content"> | |
<div class = "modal-header"> | |
<h5 class = "modal-title" id = "commentslabel">COMMENTS</h5> | |
<button type = "button" class = "close" data-dismiss = "modal" aria-label = "close"> | |
<span aria-hidden = "true">×</span> | |
</button> | |
</div> | |
<div class = "modal-body"> | |
<form action = "" method = ""> | |
<input type = "hidden" name = "viewcomm" value = "postId"> | |
</<form> | |
//I WANT THE RESULTS TO BE OUTPUT INSIDE PARAGRAPH ELEMENT BELOW | |
<p>$infoRow[user_name] : $infoRow[comments]</p> | |
<hr> | |
</div> | |
<div class = "modal-footer"> | |
<button type = "button" class = "btn btn-white" data-dismiss = "modal">close</button> | |
<button type = "button" class = "btn btn-white">Send Message</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</html> | |
</body> | |
___END; | |
} | |
$infoRow++; | |
} | |
$row++; | |
} | |
function getPostIdToCommentOn(){ | |
session_start(); | |
$user = new custom(); | |
$user->createCommentTable(); | |
$commentatorId = $_SESSION["email"]; | |
$postUniqueId = $_POST["idNumber"]; | |
$comments = $_POST["comments"]; | |
if(postId != "" && $comments != ""){ | |
$query = "INSERT INTO comments | |
VALUES(0,'$commentatorId','$postUniqueId','$comments')"; | |
mysql_query($query); | |
} | |
} | |
fetchBlogs(); | |
getPostIdToCommentOn(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment