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
https://forums.phpfreaks.com/topic/22603-how-could-i-make-a-rating-system-solved/
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]
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
[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
[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.'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.