PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 3rd, 2002, 03:26 AM
Frank Frank is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 8 Frank User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ratingsystem in PHP

Hello..

Someone know how to make/where to get a rating system like the one that is being used here at devArticles?

So we can rate on the article..

Love Frank

Reply With Quote
  #2  
Old June 3rd, 2002, 04:35 AM
infamous-online infamous-online is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 404 infamous-online User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 27 m 25 sec
Reputation Power: 8
Thumbs up

i think mytch will be writting an article on this soon
__________________
Apache Expert

Reply With Quote
  #3  
Old June 3rd, 2002, 06:00 PM
CopeLand CopeLand is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Toronto
Posts: 40 CopeLand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hey,
Annette just wrote one yesterday: http://www.devarticles.com/art/1/141 It's in ASP but it isn't too hard to translate into PHP because she explains everything.
__________________
i am cope. i drink coke. i am in hope.i am cope. i drink coke. i am in hope.i am cope. i drink coke. i am in hope.

Reply With Quote
  #4  
Old June 4th, 2002, 12:54 AM
Frank Frank is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 8 Frank User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx

Okey..

I have read it, but as a beginner I am - I don't understand so much. But I can try of course..

Tell me if anyone can come up with something smart then..

Frank

Reply With Quote
  #5  
Old June 28th, 2002, 05:54 PM
retr0 retr0 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: UK
Posts: 15 retr0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: Rating script

There is a simple rating script tutorial on my site.

http://www.developers-resources.com...2/06/26/2127157

That you can use that may help.


Retr0

Reply With Quote
  #6  
Old June 29th, 2002, 08:00 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hey Retr0,

I clicked on the link you posted, but I got an error saying that the "story could not be found." Could you post the correct link?
__________________
Sincerely,
Corbb O'Connor, Author at DevArticles

Reply With Quote
  #7  
Old July 1st, 2002, 09:55 PM
retr0 retr0 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: UK
Posts: 15 retr0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry!

Hello Web Guy

I pulled it as it as the code that the author wrote had bugs. I have done something else for my own sites rating system. I would post my own sites code but it may not be as helpful to you.

The code below should give you a good idea as to how it's done.


Database Schema / SQL Dump

Here's the SQL dump which you can use to create the required tables.
Code:
CREATE TABLE rates  (
ID int(5) DEFAULT  '0'  NOT NULL auto_increment,
FileName varchar(50)  NOT NULL,
Num_Votes int(4)  NOT NULL,
Votes int(5)  NOT NULL,
Rating int(5)  NOT NULL,
PRIMARY KEY  (ID)
);


Our table name is rates. FileName is the name of the file or article we want to rate. Num_Votes is the total number of votes for a article. Votes is the total votes calculated so far and finally Rating is the average (Num_Votes / Votes).

The script is based on the mathematical formula of Rating = Num_Votes / Votes.


Rating Page

This is where we will place the link to enable users to rate an article or a file.
Code:

<html>
<head></head>
<body>

<?php

// Define Database Conection Variables

$q="SELECT * from rates";
$result=  mysql_db_query($db_name,  $q,  $connection) or die 
("Could not execute query : $q."  .  mysql_error());

while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$FileName=$row["FileName"];
} 

?>


Rating <?php  echo  "$FileName";  ?>: <form action="<?php  echo  "rate.php?id=$id";  ?>" method="post">

<select name="Rate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<input type="submit" value="Rate">
</form>

</body>
</html>


The only thing here that you need to take note of is rate.php?id=$id which indicates that we are going to pass a id variable into rate.php.

$q="SELECT * from rates";
We use a standard select query, to output all the records in the table.

$result= mysql_db_query($db_name, $q, $connection) or die
("Could not execute query : $q." . mysql_error());

MySQL will output an error telling you what went wrong, if the query can't be executed, otherwise, it will execute the query.

while ($row=mysql_fetch_array($result))
{
$id=$row["id"];

MySQL will fetch the records row by row from the table and the record is stored in an array. We want the elements in the array and hence we have to 'explode' them out. $id=$row["id"]; will extract the id element out from the array for us.



Rating Script (rate.php)

Next we need to make a new file, named rate.php.

Code:
<?php

// SQL database Variables

$q="SELECT * from rates where id='$id'";
$result=  mysql_db_query($db_name,  $q,  $connection) or die 
("Could not execute query : $q."  .  mysql_error());

while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$Filename=$row["Filename"];
$Num_Votes=$row["Num_Votes"];
$Votes  =$row["Votes"];
$Rating=$row["Rating"];

$new_Votes=$Num_Votes+1;
$Votes=$Votes+$Rate;
$Rating=round(($Votes/$new_Votes),2); 

$q="update rates set Num_Votes='$new_Votes', Votes='$Votes', Rating='$Rating' where id='$id'";
$result=  mysql_db_query($db_name,  $q,  $connection) or die 
("Could not execute query : $q."  .  mysql_error());

if ($result) {
echo  "Thank you. The article has rating = $Rating after your vote.";
} 

}

?>


Here's the explanation for the syntax above.

$new_Votes=$Num_Votes+1;
We let new_Votes be equal to the current number of votes in the record +1. If the Num_Votes value is 5, we want $new_Votes to be 6, (5+1).

$Votes=$Votes+$Rate;
$Rate has to be exactly what you used in the html page. If a user give a vote value 5, and the current vote value in the record is 25, our $Vote will be (25+5) = 30.

$Rating=round(($Votes/$new_Votes),2);
We compute the formula for average rating, then round it up to 2 integers. round is a standard PHP function..

$q="update rates set Num_Votes='$new_Votes', Votes='$Votes', Rating='$Rating' where id='$id'";
We then update the record with our new values.[/code]
Code:
Happy hacking 

Ret0

Last edited by retr0 : July 1st, 2002 at 10:01 PM.

Reply With Quote
  #8  
Old July 2nd, 2002, 01:55 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Wow! Thanks Retr0!

Quote:
Originally posted by retr0
We compute the formula for average rating, then round it up to 2 integers. round is a standard PHP function..
What does this do? Let's say the rating comes out to 5.365892516536879, does the script then make that 5.3658925165369? Or does it make it 5.37? And if I wanted it to be 5.4, would I replace the 2 with a 1?

Thanks,
-Corbb

Last edited by WebGuy : July 8th, 2002 at 04:13 PM.

Reply With Quote
  #9  
Old July 2nd, 2002, 02:15 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
You said it!

If you want to round to the nearest tenth, just use round(value, 1);

Another function is ceil() which will round to the nearest integer value. ie: 4.56699999 will round to 5, rather than 4.6.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #10  
Old December 22nd, 2002, 10:59 PM
DivaX007 DivaX007 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 23 DivaX007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
this is a good newbie friendly tutorial

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Ratingsystem in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek