3 Replies - 770 Views - Last Post: 25 November 2008 - 12:11 AM Rate Topic: -----

#1 ajaycode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 09-August 08

web rating

Post icon  Posted 24 November 2008 - 09:33 PM

Quote

Hi everybody iam new to php how to implement the web ranking
what is the process please give me any suggetion to the ranking
wating for ur replies.
and also i want to know the how to find server ip address

advace thanks

Is This A Good Question/Topic? 0
  • +

Replies To: web rating

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5074
  • View blog
  • Posts: 13,697
  • Joined: 18-April 07

Re: web rating

Posted 24 November 2008 - 09:40 PM

One way you could do it is to setup two columns in your item (whether it be articles or code snippets or whatever) and make them both numbers. One is the total number of people who have voted. So it is a running count. The other is the sum of the ratings. So for instance if 5 people all rated something five out of five, your first column would be 5 and second one would be 25. Then on the page when you go to display you just divide one by the other... 25 / 5 = 5... the average would be 5 out of 5.

Each time someone submits a vote, you increment the first column and add their rating to the sum column and it will automatically update the rating on the page because you are doing the calculation on the fly.

:)
Was This Post Helpful? 0
  • +
  • -

#3 ajaycode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 09-August 08

Re: web rating

Posted 24 November 2008 - 11:13 PM

View PostMartyr2, on 24 Nov, 2008 - 08:40 PM, said:

One way you could do it is to setup two columns in your item (whether it be articles or code snippets or whatever) and make them both numbers. One is the total number of people who have voted. So it is a running count. The other is the sum of the ratings. So for instance if 5 people all rated something five out of five, your first column would be 5 and second one would be 25. Then on the page when you go to display you just divide one by the other... 25 / 5 = 5... the average would be 5 out of 5.

Each time someone submits a vote, you increment the first column and add their rating to the sum column and it will automatically update the rating on the page because you are doing the calculation on the fly.

:)


Quote

thanks for ur reply but allowing for voting based on ip address means one person allowed for one time vote

Thanks

Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5074
  • View blog
  • Posts: 13,697
  • Joined: 18-April 07

Re: web rating

Posted 25 November 2008 - 12:11 AM

Well next time you should be more specific about your question. We are not mind readers here.

In that case you will need a separate table which will have a foreign key which will link to the items primary key in its table. This will create a one to many relationship. 1 item can have zero or more rating records.

In this situation you will then need to figure out how many records there are and their total ratings summed up. This can be accomplished through one query which pulls all records for a given item, use a function like mysql_num_rows to get the count and then sum up their ratings. Sum / number of rows will give you the rating. Of course when they rate, you check to make sure their IP doesn't already exist in the database for the given item.

One last, less expert way, is to simply put a cookie on their machine after they have rated for an item. They can always delete the cookie and rate again, but it is up to you. They could always switch IP as well and rate again so no way is fool proof unless you require them to login to the site to rate in which case you can tie their rating to their nickname.

So its your choice.

This post has been edited by Martyr2: 25 November 2008 - 12:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1