Rateing option using php

Reply

Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Rateing option using php

 
0
  #1
Nov 2nd, 2006
Hi friendds



I need to reating the messages using php code. I need some suggestion.

For example some sites scripts are rated in ***** Tha same action im-plemet my applicaiton.

How to add ? please send me any ideas

Thanks
vssp
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Rateing option using php

 
0
  #2
Nov 2nd, 2006
You must do that yourself. Assigning a rating is merely a thing of figuring out how to rate the thing and writing the code to handle it.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Rateing option using php

 
0
  #3
Nov 3rd, 2006
Note sure what you want really. Its not too clear..

If you want to write a rating script in PHP, then what you'll have to do is.

Write a database table to hold the "item" being rated and its rating.

A simple table say item_ratings, will have the columns: id, item_id, item_type, item_name, item_rating.

NOTE: This is a generic table, which allows you to add any item that can be rated.

For example:

If you're adding a rating for a script that has the id of 2 in the db table it is listed, you just add using mysql like such: INSERT INTO item_ratings SET item_id = 2, item_type = 'script', item_name = 'Example PHP script'

Another example:

If you're adding a user to be rated, and the user_id is 4 you can do is as such: INSERT INTO item_ratings SET item_id = 4, item_type = 'user', item_name = 'Joe'


Then you'll have to create a html page (form) to rate the Items in your rating database table.

The form will then send the rating of the user to your php script and your php script will simply add this rating to your item_ratings table.

First you'll have to insert the new rating into the table.

The SQL would look like:
SELECT item_rating from item_ratings WHERE id = [id]; WHERE [id] is the id of the item being rated.

(if it doesnt exist, you can insert a row for the rating... )
If it exists, then update is.

UPDATE item_ratings SET item_rating = [new rating];

When I first thought of this problem, I thought it would be simple to add a new rating. It would be just one database entry for each Item being rated, and then each time there is a new rating, you just get the old average, and sum it with the new rating, divide by 2 and you have the new rating...

but I realized that:

pseudo code: average(a, b, c) != average( average(a, b), c);

So you cannot have just one entry in the database and keep the database normalized. You'd either have to create a new table just to link item_ratings with each rating made by a user.
It could say have the columns, item_ratings_id, rating.
And in item_ratings instead of having a column item_rating, you could make it avg_rating.
That way you can sum up all the ratings, then divide by the number of ratings to get the average.

The other way is to break normalization of your database and just have all past ratings stored in the column item_rating as TEXT.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: Rateing option using php

 
0
  #4
Nov 4th, 2006
Thansk ether

I will complete the task and let u know

vssp
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 44
Reputation: MCP is an unknown quantity at this point 
Solved Threads: 3
MCP MCP is offline Offline
Light Poster

Re: Rateing option using php

 
0
  #5
Nov 4th, 2006
Originally Posted by digital-ether View Post

When I first thought of this problem, I thought it would be simple to add a new rating. It would be just one database entry for each Item being rated, and then each time there is a new rating, you just get the old average, and sum it with the new rating, divide by 2 and you have the new rating...

but I realized that:

pseudo code: average(a, b, c) != average( average(a, b), c);

So you cannot have just one entry in the database and keep the database normalized. You'd either have to create a new table just to link item_ratings with each rating made by a user.
It could say have the columns, item_ratings_id, rating.
And in item_ratings instead of having a column item_rating, you could make it avg_rating.
That way you can sum up all the ratings, then divide by the number of ratings to get the average.

The other way is to break normalization of your database and just have all past ratings stored in the column item_rating as TEXT.
well, all you need to keep track of then is the sum and the number of ratings so that you when you get a new rating, you'd just do

UPDATE ratings SET sumRatings=sumRatings+{$newRating}, numRatings=numRatings+1 where id={$id}

then your average is just

select sumRatings/numRatings from ratings where id={$id}
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Rateing option using php

 
0
  #6
Nov 4th, 2006
Originally Posted by MCP View Post
well, all you need to keep track of then is the sum and the number of ratings so that you when you get a new rating, you'd just do

UPDATE ratings SET sumRatings=sumRatings+{$newRating}, numRatings=numRatings+1 where id={$id}

then your average is just

select sumRatings/numRatings from ratings where id={$id}
Thanks.. i knew i was missing something there...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC