Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 output x amount of characters in one specific fiel
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 March 2002 :  13:18:52  Show Profile
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.
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 02 March 2002 :  13:23:50  Show Profile
Yeah, I wonder if the reviews are all less than 20 characters.

skyhawks - how long are your reviews anyway?

Nikkol
Go to Top of Page

skyhawks
Junior Member

USA
125 Posts

Posted - 02 March 2002 :  13:58:02  Show Profile  Visit skyhawks's Homepage
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
%>

Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 02 March 2002 :  14:23:07  Show Profile
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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 March 2002 :  14:25:25  Show Profile

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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 March 2002 :  14:37:35  Show Profile
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.
Go to Top of Page

skyhawks
Junior Member

USA
125 Posts

Posted - 02 March 2002 :  18:56:43  Show Profile  Visit skyhawks's Homepage
thanks GauravBhabu, apprecriate deeply.

sky

Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 March 2002 :  19:29:10  Show Profile
You are welcome!

www.forumSquare.com - GauravBhabu - It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Go to Top of Page

skyhawks
Junior Member

USA
125 Posts

Posted - 02 March 2002 :  19:29:12  Show Profile  Visit skyhawks's Homepage
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


Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 March 2002 :  19:58:10  Show Profile
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.
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000 Version 3.4.07