User Rating Technique
Author:
Sem
First of all create a table which have value RatingID and your content id like in my logic SiteID like Comments then create a stored procedure like
CREATE PROCEDURE Q_GetRatingInfo(@SiteID int) AS
SELECT
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID AND RatingID = 1) as Rating1Count,
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID AND RatingID = 2) as Rating2Count,
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID AND RatingID = 3) as Rating3Count,
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID AND RatingID = 4) as Rating4Count,
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID AND RatingID = 5) as Rating5Count,
ISNULL((SELECT AVG(CONVERT(float, RatingID)) FROM Comments WHERE SiteID = @SiteID), 0.0) as AvgRating,
(SELECT COUNT(*) FROM Comments WHERE SiteID = @SiteID) as RatingCount
GO
then create a function AvgRating
Public Function AvgRating(ByVal SiteID As Integer) As Decimal
Dim con As New SqlConnection(myConStr) con.Open()
Dim avgrate As Decimal
Dim myCommand As SqlCommandmyCommand = New SqlCommand("Q_GetRatingInfo", con) myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.AddWithValue("@SiteID", SiteID)
Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) If reader.Read Then
avgrate = Convert.ToSingle(reader("AvgRating")) End If
con.Close()
Return avgrate End Function
User Rating Technique
Note:
RankReady
claims no responsibility for the accuracy of information in articles.
Reader Comments
Post Your Comment
Please keep your comments relevant to this article entry: inappropriate
or purely promotional comments may be removed. Email addresses are never displayed,
but they are required to confirm your comments.
Your Name(required):*
Your email address (required, will not be shown to the public): *
Your Site's URL (optional)
Do you want us to remember your personal information for next time?
Add your Comments: *
|