Seperate Fetch-JSON and fetch-SQL

This seperates the two HTML fetches to fetch-sql.php and fetch-json.php, this even means I could use both, or even provide an option to select between the submisson types. I think that however would be too much for me to maintain, so I will only use one or another. I do want to work on the datatype, and using .ini configuration for SQL and for selecting the datatype by default. If there are optimzations I can make to my SQL querys, I will try to implment those, however I know of none such optimzations.
This commit is contained in:
Evan G. 2024-06-10 16:04:25 -05:00
parent 14ba3f05c8
commit 78a1c42ed1
Signed by: fbievan
GPG Key ID: 55FAB8CB6842F080
3 changed files with 38 additions and 17 deletions

18
fetch-json.php Normal file
View File

@ -0,0 +1,18 @@
<?php
$data = json_decode(file_get_contents('test.json'), true);
echo "<div>";
foreach($data as $post) {
echo '<section class="guestbookpost">';
echo "<h4>";
echo $post["name"] . "<br>";
echo "</h4>";
echo '<h4 class="date">';
echo $post["date"] . "<br>";
echo "</h4>";
echo "<p>";
echo $post["message"] . "<br>";
echo "</p>";
echo "</section>";
}
echo "</div>";
?>

19
fetch-sql.php Normal file
View File

@ -0,0 +1,19 @@
<?php
$dbh = new PDO('sqlite:/home/evan/Development/Website-Redesign/static/guestbook/database.sq3');
$data = $dbh->query('SELECT * FROM messages')->fetchAll();
rsort($data);
foreach($data as $post) {
echo '<section class="guestbookpost">';
echo "<h4>";
echo $post["name"] . "<br>";
echo "</h4>";
echo '<h4 class="date">';
echo $post["date"] . "<br>";
echo "</h4>";
echo "<p>";
echo $post["message"] . "<br>";
echo "</p>";
echo "</section>";
}
echo "</div>";
?>

View File

@ -22,23 +22,7 @@
<input type="submit"></input>
</form>
<?php
$data = json_decode(file_get_contents('test.json'), true);
echo "<div>";
foreach($data as $post) {
echo '<section class="guestbookpost">';
echo "<h4>";
echo $post["name"] . "<br>";
echo "</h4>";
echo '<h4 class="date">';
echo $post["date"] . "<br>";
echo "</h4>";
echo "<p>";
echo $post["message"] . "<br>";
echo "</p>";
echo "</section>";
}
echo "</div>";
include("fetch-sql.php");
?>
</main>
<footer>