forked from Adleraci/adlerka.top
Test
This commit is contained in:
@@ -4,19 +4,43 @@ function getNewsArticles() :array
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
$output = ["Status" => "Fail"]; // Default Status is "Fail"
|
||||
|
||||
$articles = [];
|
||||
if (isLoggedIn()) {
|
||||
$result = $mysqli->query("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID; ");
|
||||
$stmt = $mysqli->prepare("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID; ");
|
||||
|
||||
// Check if the query executed Successfully
|
||||
if ($result) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$articles[] = $row;
|
||||
}
|
||||
$id = 0;
|
||||
$writtenAt = "";
|
||||
$writtenBy = 0;
|
||||
$title = "";
|
||||
$body = "";
|
||||
$filelist = 0;
|
||||
$writtenByName = "";
|
||||
|
||||
$stmt->bind_result($id, $writtenAt, $writtenBy, $title, $body, $filelist, $writtenByName);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
while ($stmt->fetch()) {
|
||||
$articles[] = [
|
||||
'ID' => $id,
|
||||
'WrittenAt' => $writtenAt,
|
||||
'Title' => $title,
|
||||
'Body' => $body,
|
||||
'WrittenByName' =>$writtenByName
|
||||
];
|
||||
}
|
||||
|
||||
// Check if any results were fetched
|
||||
if (!empty($articles)) {
|
||||
$output["Status"] = "Success";
|
||||
$output["Articles"] = $articles;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $articles;
|
||||
return $output;
|
||||
}
|
||||
|
||||
function addNewsArticle($title="Nazov", $body="Obsah") :array
|
||||
|
Reference in New Issue
Block a user