PDA

View Full Version : ASP Rating system help!


angst
04-19-2004, 04:37 PM
Hello,
I have a rating system on my site,
but i'm having trouble showing the rating using gaphics.
here's my code:

if rs("rating") > "5" and rs("rating") < "19" then
response.write "<img src=/images/half_star.gif border=0>"
elseif rs("rating") > "19" and rs("rating") < "29" then
response.write "<img src=/images/one_star.gif border=0>"
elseif rs("rating") > "29" and rs("rating") < "39" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/half_star.gif border=0>"
elseif rs("rating") > "39" and rs("rating") < "49" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
elseif rs("rating") > "49" and rs("rating") < "59" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/half_star.gif border=0>"
elseif rs("rating") > "59" and rs("rating") < "69" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
elseif rs("rating") > "69" and rs("rating") < "79" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/half_star.gif border=0>"
elseif rs("rating") > "79" and rs("rating") < "89" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
elseif rs("rating") > "89" and rs("rating") < "99" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/half_star.gif border=0>"
elseif rs("rating") > "99" then
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
response.write "<img src=/images/one_star.gif border=0>"
else
response.write "<font color=ff0000>rate this song!</font>"
end if

i know i have't done this right.
i need getting just the last else statment wheni run the page. and each song has a rating over 20 already.
what can i do to make his work?

thanks in advance for your time!
angst

miranda
04-19-2004, 11:46 PM
your coding looks fine. i see one thing that could be a problem. how do you have the rating stored? if it is as an integar in a database then dump the double quotes around the numbers. doublequotes are used for strings not for integars.


rating = rs("rating") ' assigning a variable makes 1 call to recordset not one
'for each instance used in the if/else statement like your original code had

if rating > 5 and rating < 19 then


I have to wonder why you don't just make new images and use them instead of using multiple images for anything greater than 1 stars? The more images you have the longer the page takes to load. if all users are on broadband or faster connection then it is mute but if you have users on dialup then speed of loading does matter.

thunderbox
04-20-2004, 12:13 AM
yea, i think it should be in one image 2, because it would take less programing and heaps less work, it would also make th epages load faster, + you could put effects on the 5 star ones, like the it flashes or sopmthing if u wanted!

oracleguy
04-20-2004, 01:14 AM
your coding looks fine. i see one thing that could be a problem. how do you have the rating stored? if it is as an integar in a database then dump the double quotes around the numbers. doublequotes are used for strings not for integars.

This is would definetly be a source of a problem. Additionally, some indenting of your code would make it easier to read.

glenngv
04-20-2004, 06:07 AM
It can be further optimized by using Select Case statement instead of If Else.

dim rating
rating = rs.Fields("rating")
Select Case True
Case (rating > 5 and rating < 19)
Response.Write("...")
Case (rating > 19 and rating < 29)
Response.Write("...")
'...
End Select