Displaying Fields On Page

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): ?>
This is article "<?php echo $article->title; ?>".
Rating: <?php echo round($article->rating); ?>/5
Rate this article: <?php foreach(range(1, 10) as $rating): ?> <?php echo $rating; ?> <?php endforeach; ?>
<?php endif; ?> [/php]

Turn on error reporting at the top of your page using these two lines:
[php]

error_reporting(E_ALL);
ini_set("display_errors", 1);

[/php]
Then, refresh the page and post your errors that are displayed. Sometimes, the errors will be displayed outside of the viewable area of your page, so sometimes you need to VIEW-SOURCE of the displayed page to see what the errors really are.

It is most likely that the fields you need to access are not in the table or you spelled them incorrectly. Let us know what the error is and what line of code it occurs on.

Sponsor our Newsletter | Privacy Policy | Terms of Service