Jump to content

How to handle reviews?


ZionBludd
 Share

Recommended Posts

Hi everybody. I just wanted to start by saying what a great support forum this is so far, was blown away by my first post!  I have since managed to get a lot of my project working, but am now stuck on a pretty major part. The reviews system. This was before handled by a plugin (Wordpress). 

My website is a reviews website that focuses on the fitness industry... The website consists of three parts

  1. Homepage
  2. Search Results Page
  3. Listing Page

I am wanting to implement a reviews section on each page, basically defined by the title of the page. I have created for this purpose my own table, independent of PW, just due to the fact I suspect this will be a very large database table and don't want to have stability issues later on down the track. Should I be using PW's field_ tables or?

Here is my current code 

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "app";
 
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
 
$sql = "SELECT id, review_author, review_body, date_submitted, listing_name FROM reviews";
$result = $conn->query($sql);
 
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["review_author"]. " - Name: " . $row["review_body"]. " " . $row["date_submitted"]. "<br>";
    }
} else {
    echo "No reviews found";
}
$conn->close();
?>

I am very much at the beginning of learning PHP, and would love some guidance on how to move forward. 

Cheers

Link to comment
Share on other sites

Of course you can totally roll your own table and SQL, but the “ProcessWire way” would be to have a Review template and a separate page for each review. There are a couple of different ways to model the relation between reviews and their pages, the simplest being just making them children. So you’d have

--Listing (?? or whatever)

----Review 1

----Review 2

If you don’t want to pollute your page tree with this, and/or have the convenience of editing reviews directly from the page edit screen, you may use a page field, a page table field, or possibly a repeater field. PageTable would probably provide the nicest UI for editors, if that’s a concern.

If you’re interested in accessing the database, these threads about the $db variable may also be of interest:

Functions/methods to access the DB?

Reading and displaying data from a custom table

  • Like 1
Link to comment
Share on other sites

hi mattcohen,

welcome to the forum!

your code looks like you have not yet fully understood what processwire is and can do for you to make your life easy ;) the key to success is structuring your content, then you can easily access all your data by simple

foreach ($page->children() as $review) {
    echo $review->title ... $review->body ... $review->rating ... and so on
}

maybe this is a good read for you: https://processwire.com/talk/topic/3579-tutorial-approaches-to-categorising-site-content/

did you go through the hello world tutorial? https://processwire.com/docs/tutorials/hello-worlds/

  • Like 1
Link to comment
Share on other sites

There is a comments fieldtype that makes adding comments to pages a breeze.

Since reviews are some kind of 'comments', maybe you can use that module and then extend it to add a rating star system.

EDIT

here's a thread about adding additional fields to the comments system https://processwire.com/talk/topic/2898-adding-additional-fields-to-comments/

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...