Skip to content

Instantly share code, notes, and snippets.

@CharlesCraft50
Created May 1, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlesCraft50/fc470bdd9b8edfe18f114dc6f15171e5 to your computer and use it in GitHub Desktop.
Save CharlesCraft50/fc470bdd9b8edfe18f114dc6f15171e5 to your computer and use it in GitHub Desktop.
<?php
include('database.php');
$searchByOrder = $_REQUEST["SubjectNamePostsOrderBy"];
if($searchBy = $conn->prepare("SELECT * FROM PostData WHERE SubjectName LIKE ? ORDER BY " . $searchByOrder . "")) {
$searchLikeBy = "%" . $_REQUEST["SubjectNamePostsLike"] . "%";
$searchBy->bind_param('s', $searchLikeBy);
$searchBy->execute();
$searchBy->bind_result($Id, $UserName, $SubjectName, $PostDataPost, $MainImage, $DatePosted, $PostViews, $UpVoted, $DownVoted);
while($searchBy->fetch()) {
if($PostUpVotes = $conn->prepare("SELECT * FROM PostVotes WHERE SubjectName = ? AND VoteType = 'UpVoted'")) {
$PostUpVotes->bind_param('s', $SubjectName);
$PostUpVotes->execute();
$PostUpVotes->store_result();
$postUpVResult = $PostUpVotes->num_rows();
echo "<script>$(\"#UpVoteThis\").html(\"" . "<img src=\\\"UpVoted-Icon.png\\\" width=\\\"30\\\" height=\\\"30\\\"></img> " . $postUpVResult . "" . "\");</script>";
} else {
echo "<pre>Error UpVoting, Error: " . $conn->error . "</pre>";
}
if($PostDownVotes = $conn->prepare("SELECT * FROM PostVotes WHERE SubjectName = ? AND VoteType = 'DownVoted'")) {
$PostDownVotes->bind_param('s', $SubjectName);
$PostDownVotes->execute();
$PostDownVotes->store_result();
$postDownVResult = $PostDownVotes->num_rows();
echo "<script>$(\"#DownVoteThis\").html(\"" . "<img src=\\\"DownVoted-Icon.png\\\" width=\\\"30\\\" height=\\\"30\\\"></img> " . $postDownVResult . "" . "\");</script>";
} else {
echo "<pre>Error DownVoting, Error: " . $conn->error . "</pre>";
}
echo "<pre style=\"background-color: #fafafa; border-left: 3px solid #333;\"><a href=\"?SubjectName=" . $SubjectName . "\"><h3>" . $SubjectName . "</h3></a><p style=\"font-size: 13px; display: inline; color: #9197a3;\">User Posted: " . $UserName . " </p><p style=\"font-size: 13px; display: inline; color: #9197a3;\">Date Posted: " . $DatePosted . " </p><div id=\"descArea\"><br>" . $PostDataPost . "</div><br>" . "<img src=\"" . $MainImage . "\" style=\"max-width: 500px; max-height: 500px;\"></img><img src=\"DownVoted-Icon.png\" width=\"30\" height=\"30\"></img> " . $DownVoted . "<br><div style=\"font-size: 13px; display: inline; color: #9197a3;\">Views: " . $PostViews . "</div></pre><p style=\"border: 1px solid transparent; border-bottom: 1px solid black; \"></p>";
}
} else {
echo "Problem Loading Index Post Data! Error: " . $conn->error;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment