Hello,
So I have followed a tutorial to make a rating system. I followed it exactly so I could get everything work correctly, which it is. The video is called “PHP Star Rating System” by code course on youtube.
Now that I have it all work correctly. I want to add some fields such as timestamp. So that it is displayed on the screen.
Everytime I try to change any of the code on article.php the page fails to load correctly. what exactly do I need to do to the following code to make it pull other selected fields.
This is a page called article.php and it displays the following:
This is article: “Article 1”.
Rating: 8/5
Rate this article: 1 2 3 4 5 6 7 8 9 10
I want article.php to display with more information like this:
This is article: “Article 1”.
This article was added: 2016-07-03 17:08:22
Another Field: test_field_1
Another Field: test_field_2
Rating: 8/5
Rate this article: 1 2 3 4 5 6 7 8 9 10
Table: articles
Field: id
Field: title
Field: timestamp
Code that needs to be updated so article.php will display all the fields that I want:
[php]<?php
require_once ‘app/init.php’;
$article = null;
if(isset($_GET[‘id’])) {
$id = (int)$_GET['id'];
$article = $db->query("
SELECT articles.id, articles.title, AVG(articles_ratings.rating) AS rating
FROM articles
LEFT JOIN articles_ratings
ON articles.id = articles_ratings.article
WHERE articles.id = {$id}
")->fetch_object();
}
?>
<!doctype html>
Article <?php if($article): ?>