Jump to content

How could i make a rating system *solved*


Renlok

Recommended Posts

heres what happens. theres a search bar you search for anything from the database and the search results are posted on the page.

what i what to be able to happen is a viewer to be able to give a rating to the database entries and the current rating to be shown when there posted on the page.
but i have no idea how to do this anyone have any ideas
Link to comment
Share on other sites

You are going to need a db table to hold the viewers ratings.

ratings table
-------------
rating_id
database_item_id
rating_value

That's the minimum you need. Add a record each time someone rates a db item.

(If you want safeguards to stop people rating an item several times then you are going to need to store something to identify the viewer too.)

To get the rating for an item

[code]
SELECT AVG(rating_value) FROM ratings WHERE database_item_id = '$item_id'

[/code]
Link to comment
Share on other sites

i have used you idea but my tables names are changes slightly here is my code i used

[code]$URL = ($row['url']);
$rate_query = "SELECT AVG(ratingValue) FROM rating WHERE URL = '$URL'";
$rate_result = $db->query($rate_query);
echo '<br><u>Rating:</u> '.$rate_result.'<br>';
if ($rate_query == 0);
{
echo 'This entry has not yet been rated.';
}[/code]

but it will just show 'Object id #4' i dont know why
Link to comment
Share on other sites

[code]$URL = ($row['url']);        //url is primary key in main database
$rate_query = "SELECT AVG(ratingValue) FROM rating WHERE URL = '$URL'";
$row = $db->fetch_row();
$rate_result = $row[0];
echo '<br><u>Rating:</u> '.$rate_result.'<br>';
if ($rate_query == 0);
{
echo 'This entry has not yet been rated.';
}[/code]

Fatal error: Call to undefined method mysqli::fetch_row() in /home/renlok/public_html/results.php on line 74
Link to comment
Share on other sites

[code]$URL = ($row['url']);
$rate_query = "SELECT ratingValue FROM rating WHERE URL = '$URL'";
$rate_result = $db->query($rate_query);
$num_results = $rate_result->num_rows;
$avg = +$rate_result/$num_results;
echo '<br><u>Rating:</u> '.$avg.'<br>';
if ($rate_query == 0);
{
echo 'This entry has not yet been rated.';
}
[/code]

this is my most resent attempt also not working will show rating as 1 no matter what the actual rating is it also always shows 'This entry has not yet been rated.'
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.