Jump to content

Archived

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

Renlok

How could i make a rating system *solved*

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

Share this post


Link to post
Share on other sites
There are a couple of rating tutorials around on the internet you could check out some of them. If you can't find a good one lemme know and i'll find the one i used.

Peter.

Share this post


Link to post
Share on other sites
http://www.google.com/search?hl=en&q=php+rating+system

Too many of them...

Orio.

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
$rate_result is the recordset returned by the query. You need to get the first field from the first row of that recordset.

Share this post


Link to post
Share on other sites
and how would i go around doing that?
lol im new to this

Share this post


Link to post
Share on other sites
I don't jnow what class you are using.

If it's mysqli, then
[code]
$row = $db->fetch_row();
$rate_result = $row[0];
[/code]

Share this post


Link to post
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

Share this post


Link to post
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.'

Share this post


Link to post
Share on other sites
[code]
<?php
$rate_result = $db->query($rate_query);
$row = $rate_result->fetch_row();
$avg = $row[0];
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.