add post viewing basis, add insert post and comment queries
This commit is contained in:
97
website/queries/post.php
Normal file
97
website/queries/post.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
function selectPostById($postID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`user`.`fname`,
|
||||
`user`.`lname`,
|
||||
`user`.`username`,
|
||||
`post`.`groupID`,
|
||||
`post`.`title`,
|
||||
`post`.`content`,
|
||||
`post`.`creationdate`
|
||||
FROM
|
||||
`post`
|
||||
INNER JOIN
|
||||
`user`
|
||||
ON
|
||||
`post`.`author` = `user`. `userID`
|
||||
WHERE
|
||||
`post`.`postID` = :postID
|
||||
");
|
||||
|
||||
$stmt->bindParam(':postID', $postID);
|
||||
$stmt->execute();
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function selectCommentsByPostId($postID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`comment`.`commentID`,
|
||||
`comment`.`postID`,
|
||||
`comment`.`author`,
|
||||
`comment`.`content`,
|
||||
`comment`.`creationdate`,
|
||||
`user`.`fname`,
|
||||
`user`.`lname`,
|
||||
`user`.`username`
|
||||
FROM
|
||||
`comment`
|
||||
INNER JOIN
|
||||
`user`
|
||||
ON
|
||||
`comment`.`author` = `user`.`userID`
|
||||
WHERE
|
||||
`comment`.`postID` = :postID
|
||||
");
|
||||
|
||||
$stmt->bindParam(':postID', $postID);
|
||||
$stmt->execute();
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function makePost($userID, $groupID, $title, $content) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
INSERT INTO
|
||||
`post` (
|
||||
`author`,
|
||||
`groupID`,
|
||||
`title`,
|
||||
`content`
|
||||
)
|
||||
VALUES (
|
||||
:userID,
|
||||
:groupID,
|
||||
:title,
|
||||
:content
|
||||
)
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $userID);
|
||||
$stmt->bindParam(':groupID', $groupID);
|
||||
$stmt->bindParam(':title', $title);
|
||||
$stmt->bindParam(':content', $content);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function makeComment($postID, $userID, $content) {
|
||||
$stmt = $_GLOBAL["db"]->prepare("
|
||||
INSERT INTO
|
||||
`comment` (
|
||||
`postID`,
|
||||
`author`,
|
||||
`content`
|
||||
)
|
||||
VALUES (
|
||||
:postID,
|
||||
:userID,
|
||||
:content
|
||||
)
|
||||
");
|
||||
|
||||
$stmt->bindParam(':postID', $postID);
|
||||
$stmt->bindParam(':userID', $userID);
|
||||
$stmt->bindParam(':content', $content);
|
||||
$stmt->execute();
|
||||
}
|
||||
Reference in New Issue
Block a user