Continue....

Want to just show a snippet from each record, and then show a couple dots at the end of the text if there is more text beyond what you are showing on the screen?

We are giving you two different examples here. The first one just shows how to automatically display 50 characters of text from a "DESCRIP" field, and if the description is longer than 50 characters, then show a couple dots (..) at the end of the string (indicating that there is more text to see), else don't show anything at all.

The second example we have here will actually hyperlink the record to itself. Instead of just showing the two dots, it will say "Read More..", which will be hyperlinked to the records ID (PID). When clicked, it will reload this same file and display just that one particular record.

Make sure you have a connection already setup to your database, a table in that database named: TABLE, and three fields in that table named: PID, PNAME, and DESCRIP.
For demonstration purposes only! Please be aware of SQL Injection, and techniques to avoid.
<%@ LANGUAGE = "VBScript" %>
 <%
 Set cnDZ = Server.CreateObject("ADODB.Connection")
 cnDZ.Open "DSN=myDatabase"
 %>
 <html>
 <head><title>players.asp</title></head>
 <body>
 <%
 Set rs = cnDZ.Execute("SELECT * FROM TABLE")
 If Not rs.EOF Then
 Do Until rs.EOF
 If Len(rs("DESCRIP")) > 50 Then dot = ".." Else dot = ""
 Response.Write"Player Name: "&rs("PNAME")&"<br>"&_
   "Description: "&Left(rs("DESCRIP"),50)&""&dot&"<br><br>"
 rs.MoveNext
 Loop
 Else Response.Write"Sorry, no records found."
 End If
 rs.Close
 Set rs = Nothing
 %>
 
<br><br><br>
 
<%
 'Or, the second, more intense example
 'hyperlinking the record to itself:
 specific = Request.QueryString("specific")
 If specific = "" Then
 Set rs = cnDZ.Execute("SELECT PID, PNAME, DESCRIP FROM TABLE ORDER BY PNAME ASC")
 If Not rs.EOF Then
   Do Until rs.EOF
   If Len(rs("DESCRIP")) > 50 Then dot = " <a href=""players.asp?specific="&rs("PID")&""">Read More..</a>" Else dot = ""
   Response.Write"Player Name: "&rs("PNAME")&"<br>"&_
    "Description: "&Left(rs("DESCRIP"),50)&""&dot&"<br><br>"
   rs.MoveNext
   Loop
 Else Response.Write"Sorry, no records found."
 End If
 rs.Close
 Set rs = Nothing
 Else
 Set rs = cnDZ.Execute("SELECT * FROM TABLE WHERE PID = "&specific&"")
 If Not rs.EOF Then
   Response.Write"Player Name: "&rs("PNAME")&"<br>"&_
    "Description: "&rs("DESCRIP")&""
 Else Response.Write"Sorry, that record was not found."
 End If
 rs.Close
 Set rs = Nothing
 End If
 %>
 </body>
 </html>


dot dot dot more


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site