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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count, trim, Write Link

Status
Not open for further replies.

mikecx

Technical User
Jul 9, 2002
215
US
If I am pulling info from a db to write news and I want it to count the total number of words, trim it to 250, then print a link to that page how would i go about doing it? I can post the code if needed.
 
Function WriteNews()
Const NumPerPage = 5
Dim Db, Rs
Dim strSQL, strScriptName, strTitle, strText
Dim iCurrentPage, iTotalPages, iCount

strScriptName = Request.ServerVariables("SCRIPT_NAME")

If Request.QueryString("page") = "" Then
iCurrentPage = 1
Else
iCurrentPage = CInt(Request.QueryString("page"))
End If

strSQL = "SELECT dbo.News.Title, dbo.News.Author, dbo.News.DateWritten, dbo.News.TimeWritten, " &_
"dbo.News.Text FROM dbo.News ORDER BY dbo.News.id DESC"

Set Db = Server.CreateObject("ADODB.Connection")
Db.ConnectionTimeOut = Application("****_ConnectionTimeout")
Db.Open "Provider=****;User ID=****;Password=****;Initial Catalog=****;Data Source=****;", Application("****_RunTimeUserName"), Application("****_RunTimePassword")

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open strSQL, Db, 1, 1

If Rs.BOF And Rs.EOF Then
Response.Write("No news? Either a DB problem or a quiet admin.")
Else
If Not Rs.EOF Then
Rs.MoveFirst
Rs.PageSize = NumPerPage
iTotalPages = Rs.PageCount
Rs.AbsolutePage = iCurrentPage
End If

If Not iCurrentPage = 1 Then
Response.Write(&quot;<center><font size=&quot;&quot;1&quot;&quot;><a href=&quot;&quot;&quot; & strScriptName & &quot;?page=&quot; & iCurrentPage - 1 & &quot;&quot;&quot;>Next &quot; & NumPerPage & &quot; posts</a> | &quot;)
Else
Response.Write(&quot;<center><font size=&quot;&quot;1&quot;&quot;>| &quot;)
End If

If Not iCurrentPage = iTotalPages Then
Response.Write(&quot;<a href=&quot;&quot;&quot; & strScriptName & &quot;?page=&quot; & iCurrentPage + 1 & &quot;&quot;&quot;>Prev &quot; & NumPerPage & &quot; posts</a></font></center> <br />&quot;)
Else
Response.Write(&quot;</font></center><br />&quot;)
End If

Do While Not Rs.EOF And Count < Rs.PageSize
strTitle = Rs(0)
strTitle = Replace(strTitle, &quot;%@%&quot;, &quot;'&quot;)

strText = Rs(4)
strText = Replace(strText, &quot;%@%&quot;, &quot;'&quot;)

Response.Write.Count(&quot;<font color=&quot;&quot;#000000&quot;&quot; size=&quot;&quot;5&quot;&quot;><b>&quot; & strTitle & &quot;  </b></font>&quot; &_
&quot;<font color=&quot;&quot;#123456&quot;&quot; size=&quot;&quot;2&quot;&quot;>[<a href=&quot;&quot;mailto:&quot; & Rs(1) & &quot;@designpeak.com&quot;&quot;>&quot; & Rs(1) & &quot;</a>] &quot; & Rs(2) & &quot; - &quot; & Rs(3) & &quot;</font>&quot; &_
&quot;<br />&quot; & CheckEmoticons_Index(strText) & &quot;<br /><br />&quot;)

Rs.MoveNext()
Count = Count + 1
Loop

If Not iCurrentPage = 1 Then
Response.Write(&quot;<center><font size=&quot;&quot;1&quot;&quot;><a href=&quot;&quot;&quot; & strScriptName & &quot;?page=&quot; & iCurrentPage - 1 & &quot;&quot;&quot;>Next &quot; & NumPerPage & &quot; posts</a> | &quot;)
Else
Response.Write(&quot;<center><font size=&quot;&quot;1&quot;&quot;>| &quot;)
End If

If Not iCurrentPage = iTotalPages Then
Response.Write(&quot;<a href=&quot;&quot;&quot; & strScriptName & &quot;?page=&quot; & iCurrentPage + 1 & &quot;&quot;&quot;>Prev &quot; & NumPerPage & &quot; posts</a></font></center><br />&quot;)
Else
Response.Write(&quot;</font></center><br />&quot;)
End If
End If

Rs.Close()
Db.Close()

Set Rs = Nothing
Set Db = Nothing
End Function
%>

I need to make that trim the text that it gets from the database to 250 characters, and write the name of the the post as the name of the html link to the full news posting.
 
For the total number of words you could count the number of spaces in the content and get a pretty good estimate.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top