Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit amount of text displayed from db article w/ link to full article 1

Status
Not open for further replies.

auger

Technical User
Oct 27, 2001
48
CA
I have a problem displaying some text on an ASP page.

My page pulls articles from a db. The last 5 articles in my db are displayed in descending order on my ASP page. Some of the articles are rather long and are written to the browser as follows:

strTitle = objRS("Title")
strStory = objRS("Story")
strLink = objRS("Link")
strSubmittedBy = objRS("SubmittedBy")
strDatestamp = objRS("Datestamp")

Response.Write &quot;<p><a name='&quot; & numCounter & &quot;'></a><b>&quot;
Response.Write strTitle
Response.Write &quot;</b><br>&quot;
##Response.Write strStory
Response.Write &quot;<br><br>&quot;
Response.Write &quot;Link: <a href='&quot; & strLink & &quot;' target='_new'>&quot; & strLink & &quot;</a>&quot;
Response.Write &quot;<br>&quot;
Response.Write &quot;<small>Submitted by &quot;
Response.Write strSubmittedBy
Response.Write &quot; on &quot;
Response.Write strDatestamp
Response.Write &quot;</small></p>&quot;
Response.Write &quot;<hr width='75%'>&quot;

numCounter = numCounter + 1
objRS.MovePrevious

Loop

objRS.Close
'objConn.Close
Set objRS = Nothing
Set objConn = Nothing
%>

Because some of the articles are long, I want clean up the page by limiting the amount of text that displays to 150-200 characters.

I've tried to alter my code by eliminating the line of code I've notated with '##' (above) with several variations of this code:

Response.Write Left(Trim((strStory).value), 150)
if Len(Trim((strStory).value)) > 150)
Response.Write &quot;...<a href='showstory.asp?storyid=&quot; & numID & &quot;'>Full Story&gt;&gt;&gt;&quot;
Response.Write &quot;<br><br>&quot;

I was hoping to limit the article to 150 characters and provide a link to the full article with &quot;Full Story>>>&quot;

The closest I've come to success has been to write the first article Headline and the following error:

Microsoft VB Script Runtime Error '800a01a8'

Object required: '[string:&quot;<p>A small snippet of article text here&quot;]'

line 59

where line 59 is:

Response.Write Left(Trim((strStory).value), 150)

I'm confused but I'm wondering if the error is being produced because of the way that my articles are submitted to the db...

I submit articles to the db via web form. The text in the web form includes HTML formatting tags such as <p> <b> etc. Could this error occur because I'm trimming my text down to 150 characters and by doing so am producing a string of text (that I want to display in a condensed form) but it's missing the </p> tag?

If anyne can help me with the code, or suggest some alternatives to achieve the same end (partial articles with links to full article) I'd be very appreciative.

This line of code sucesfully produces an ASP page (showstory.asp) with the full article:

Response.Write &quot;...<a href='showstory.asp?storyid=&quot; & numID & &quot;'>&quot;

So close and yet so far...

Thanks in advance.








and I want to limit the amount of displayed text to a couple of hundred characters or so.

 
You can select the first X amount of characters from a database field by useing the LEFT() function like so:

<%
'make database connection and retrieve desired record
Dim message
message = Left(rs(&quot;userMessage&quot;),150) 'First 150 characters

Response.write(message)
%>

Then just Make a link to another page with a queryString veriable holding the PK field of the record desired and display the full message.

<A href=&quot;fullMessage.asp?msgID=&quot;<%= rs(&quot;userMessagePK&quot;)%>&quot;>See the whole message</A>



Next Page...
<%
Dim id
id = Request.QueryString(&quot;msgID&quot;)
sql = &quot;SELECT * FROM userMessages WHERE ((userMessages.userMessagePK)=&quot; & id & &quot;);&quot;

'retrieve message and display the whole message.
%>

Hope this is what you were looking for.
-Ovatvvon :-Q
 
Thanks Ovatvvon. It took a whole afternoon of tweaking but I have it set up now exctly as I wanted it to be. Very helpful. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top