Author |
Topic |
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 March 2002 : 13:18:52
|
I want to know if the use of Instr is causing to return nothing. That is why I suggested not to use Instr as in my post above
www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 02 March 2002 : 13:23:50
|
Yeah, I wonder if the reviews are all less than 20 characters.
skyhawks - how long are your reviews anyway?
Nikkol |
|
|
skyhawks
Junior Member
USA
125 Posts |
Posted - 02 March 2002 : 13:58:02
|
GauravBhabu, you wrote. <%=Left(rs("review"),100)%> <%=Mid(rs("review"),1,100)%>
my answer: yes they work.. it give me 100 characters.
Nikkol... your code on instr.
I didnt get to try that... reason because I rewrote my code.. and everything seem to work. see below under working code.
also, you asked how many characters do i have in my data records, it has more than 200 characters.
<%= Left(rs("review"), Instr(100, rs("review"), ".",1)) %>
GauravBhabu, the above code you gave me do work... if I dont do the random. see if you can resolve it. this was the code i was using..
<html><head><title></title></head><body> <% dim conn, rs, recCount, rec
set conn=server.CreateObject("adodb.connection") set rs=server.CreateObject("adodb.recordset") conn.Open "nydb" strsql = "Select ID FROM movie" rs.Open strsql, conn, 3 recCount = rs.RecordCount
rs.close conn.Close set rs=nothing set conn=nothing
randomize rec = int(rnd * recCount)
set conn=server.CreateObject("adodb.connection") conn.open "nydb" strsql = "Select ID, imgposter, movietitle, review FROM movie" set rs=conn.execute(strsql)
rs.MoveFirst rs.Move rec %>
<p><img src="/posters/<%= rs("imgposter") %>" border=0> <b><%= rs("movietitle") %></b><br> <%= Left(rs("review"), Instr(100, rs("review"), ".", 1)) %> <a href="/moviereview.asp?ID=<%= rs("ID") %>">more</a></p>
<% rs.Close conn.close set rs=nothing set conn=nothing %>
</body></html>
Well, heres the code that seem to be working now.. of course in the response.write, i will lay it out a little bit better....
-- working code --
<% set conn = server.createobject("adodb.connection") conn.open "nydb" set rs=server.CreateObject("adodb.recordset") strsql = "Select * FROM movie" rs.Open strsql, conn, 1, 3
recTotal=rs.recordcount
randomize random_number=int(rnd*recTotal)+1
rs.MoveFirst
do while not rs.eof and counter <> random_number
counter = counter + 1
if counter= random_number then Response.Write rs("imgposter") & "<br>" Response.Write rs("movietitle") & "<br>" Response.Write Left(rs("review"), Instr(100, rs("review"), ".", 1)) &"<br>" Response.Write rs("ID") & vbNewLine end if
rs.movenext loop %>
|
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 02 March 2002 : 14:23:07
|
With the code that works, do you get a different review every time?
What happens if you modify the code like so: recCount = CInt(rs.RecordCount) ' first non-working sample recTotal = CInt(rs.recordcount) ' second working sample
Nikkol |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 March 2002 : 14:25:25
|
set conn=server.CreateObject("adodb.connection") conn.open "nydb" strsql = "Select ID, imgposter, movietitle, review FROM movie" rs.Open strsql, conn, 1, 3 recTotal=rs.recordcount rs.MoveFirst Rem ----This is the syntex for getting the Randomn number from a range Rem ----Randomn Number = Int(((upperbound - lowerbound + 1) * Rnd) + lbound) Rem ----So this is how you should determine to get the position for a Randomn Record Randomize() Rec = Int(((recTotal - 1 + 1) * Rnd) + 1) rs.Move Rec Response.Write rs("imgposter") & "<br>" Response.Write rs("movietitle") & "<br>" Response.Write Left(rs("review"), Instr(100, rs("review"), ".", 1)) &"<br>" Response.Write rs("ID") & vbNewLine rs.close set rs = nothing
www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Edited by - GauravBhabu on 02 March 2002 14:30:32 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 March 2002 : 14:37:35
|
Look here for a script I built to get Randomn Records
Randomn Records
www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
|
|
skyhawks
Junior Member
USA
125 Posts |
Posted - 02 March 2002 : 18:56:43
|
thanks GauravBhabu, apprecriate deeply.
sky
|
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 March 2002 : 19:29:10
|
You are welcome!
www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
|
|
skyhawks
Junior Member
USA
125 Posts |
Posted - 02 March 2002 : 19:29:12
|
GauravBhabu,
the last set of code you wrote out in hte above message.. sometimes i get this error message. do you know why??
ADODB.Field error '80020009'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/home.asp, line 0
|
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 March 2002 : 19:58:10
|
rs.Move Rec
Change this statement as below
rs.Move (Rec - 1)
www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying. |
|
|
Topic |
|