
24/07/2004, 23:13
|
 | | | Fecha de Ingreso: noviembre-2002 Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 6 meses Puntos: 16 | |
Problemas con un código Hola amigos agradeceria su ayuda para encontrar el problema en este código.. Show.asp
Código:
<%
dim conn
dim rs
set conn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("cds.mdb")
conn.Open strCon
rs.ActiveConnection = conn
rs.Open "SELECT * FROM cds ORDER BY title ASC"
while not rs.EOF
%>
<font face="Verdana" size="2" color="black">
<h2><%=rs.Fields(1).Value%></h2>
<b>Author:</b> <%=rs.Fields(2).Value%><br>
<b>Summary:</b> <%=rs.Fields(3).Value%><br>
<b>Price:</b> <%=FormatCurrency(rs.Fields(4).Value, 2)%><br>
</font>
<br>
<form name="frmRate<%=rs.Fields(0).value%>" action="rate.asp">
<input type="hidden" name="cdId" value="<%=rs.Fields(0).value%>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="black">
<font face="Verdana" size="1" color="white">
<%
for i = 1 to 10
Response.Write " " & i & " <input name=""rating"" type=""radio"" value=""" & i & """> "
next
%>
</font>
<input type="submit" value="Rate It!">
</td>
</tr>
</table>
</form>
<hr size="1" color="#08496B" NOSHADE>
<%
rs.MoveNext
wend
%>
Rate.asp
Código:
<%
dim conn
dim rs
dim cdId
dim visitorIP
dim rating
dim cookie
dim cookieRated
cdId = Request.Form("cdId")
rating = Request.Form("rating")
visitorIP = Request.ServerVariables("REMOTE_ADDR")
cookie = Request.Cookies("rate_" & cdId)
set conn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("cds.mdb")
conn.Open strCon
rs.ActiveConnection = conn
if cookie = "" then
cookieRated = false
else
cookieRated = true
end if
if rating = "" then
'Invalid rating
%>
<font face="Verdana" size="2" color="black">
<h2>Invalid Rating</h2>
You must select a rating first!<br><br>
<a href="javascript:history.go(-1)">Go Back</a>
</font>
<%
else
'Valid rating, make sure visitor hasn't already voted
'by checking the ratings table
rs.Open "SELECT COUNT(*) FROM ratings WHERE ip='" & visitorIP & "' AND cdId=" & cdId
if rs.Fields(0).Value = 0 then
if cookieRated = false then
'Visitor hasn't rated yet, let's add it
conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", '" & visitorIP & "', " & cdId & ")"
Response.Cookies("rate_" & cdId) = true
Response.Cookies("rate_" & cdId).expires = Date() + 30
%>
<font face="Verdana" size="2" color="black">
<h2>Thank You For Rating!</h2>
Your CD rating has been added to our database.<br><br>
<a href="showcds.asp">Continue</a>
</font>
<%
else
'Visitor has already rated this article
%>
<font face="Verdana" size="2" color="black">
<h2>Already Rated</h2>
You have already rated this article!<br><br>
<a href="javascript:history.go(-1)">Go Back</a>
</font>
<%
end if
%>
<%
else
'Visitor has already rated this article
%>
<font face="Verdana" size="2" color="black">
<h2>Already Rated</h2>
You have already rated this article!<br><br>
<a href="javascript:history.go(-1)">Go Back</a>
</font>
<%
end if
%>
<%
end if
%>
Showrating.asp
Código:
<%
function ShowRating(cdId)
const MIN_RATINGS_BEFORE_SHOW = 3
dim rs1
dim avgRating
dim avgWhole
dim decPart
dim decCalc
dim finalRating
dim altText
set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.ActiveConnection = conn
rs1.Open "SELECT SUM(rating), COUNT(*) FROM ratings WHERE cdId = " & cdId
if rs1.Fields(1) < MIN_RATINGS_BEFORE_SHOW then
'No ratings for this CD just yet
Response.Write "[CD not rated yet]"
else
'This CD has ratings, let's display the average
avgRating = rs1.Fields(0).Value / rs1.Fields(1).Value
if Instr(1, CStr(avgRating), ".") > 0 then
'The average rating is a decimal, we need to either
'round the value up/down
avgWhole = Left(CStr(avgRating), Instr(1, CStr(avgRating), ".")-1)
decPart = Mid(CStr(avgRating), Instr(1, CStr(avgRating), ".")+1, 2)
if decPart <> "" then
'Work out whether or not we have to round this
'rating up or down
if CInt(decPart) >= 5 then
decCalc = .5
else
decCalc = 0
end if
finalRating = CInt(avgWhole) + CCur(decCalc)
else
finalRating = avgRating
end if
else
finalRating = avgRating
end if
'Setup the alt text for the images
altText = "Average visitor rating of " & finalRating & " out of 10"
for i = 1 to CInt(finalRating)
Response.Write "<img alt='" & altText & "' src='rating_on.gif'>"
next
if CInt(finalRating) <> finalRating then
'This article has a .5 rating, such as 5.5
Response.Write "<img alt='" & altText & "' src='rating_half.gif'>"
for i = CInt(finalRating)+2 to 10
Response.Write "<img alt='" & altText & "' src='rating_off.gif'>"
next
else
for i = CInt(finalRating)+1 to 10
Response.Write "<img alt='" & altText & "' src='rating_off.gif'>"
next
end if
%>
En el navegador me tira errores de tipo de sintaxis como se esperaba End y cosas asi no se que puede ser en todo caso si quieren probar el script entero la base de datos contiene los siguientes campos:
Tabla cds:
cdId--------Autonumérico
title---------texto
artist--------texto
summary---texto
price--------numérico
Tabla ratings:
ratingId-------autonumérico
rating---------numérico
ip--------------numérico
cdId-----------numérico
Bueno de antemano muchas gracias y adios
__________________ Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!! |