Jump to content


Photo

How could i make a rating system *solved*


  • Please log in to reply
12 replies to this topic

#1 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 30 September 2006 - 04:59 PM

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

#2 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 30 September 2006 - 05:53 PM

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.

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 September 2006 - 05:54 PM

http://www.google.co...p rating system

Too many of them...

Orio.
Think you're smarty?

(Gone until 20 to November)

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 30 September 2006 - 07:12 PM

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

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


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 04 October 2006 - 10:56 PM

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

$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.';
}

but it will just show 'Object id #4' i dont know why

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 04 October 2006 - 11:01 PM

$rate_result is the recordset returned by the query. You need to get the first field from the first row of that recordset.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 05 October 2006 - 06:59 AM

and how would i go around doing that?
lol im new to this

#8 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 05 October 2006 - 03:49 PM

anyone?

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 05 October 2006 - 05:11 PM

I don't jnow what class you are using.

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 05 October 2006 - 05:57 PM

$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.';
}

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

#11 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 06 October 2006 - 07:07 AM

$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.';
}

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.'

#12 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 06 October 2006 - 07:49 AM

<?php
$rate_result = $db->query($rate_query);
$row = $rate_result->fetch_row();
$avg = $row[0];
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#13 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 06 October 2006 - 02:46 PM

thanks for all the help it now works.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users