Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2003, 04:55 AM
CW CW is offline
Authorized User
 
Join Date: Sep 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hyperlink

Hi.

I love this place :-)

I have an asp script which can retrieve a data from ms access database and it can be diplayed in Table.

There are more than one field in the database. My question is :
How can i make one field as hyperlink while others are not.
at the same time they are all displayed in table.

Thanks in advance.

rgds

CW

 
Old September 16th, 2003, 04:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Well it depends on how you do your table - show us some code...

 
Old September 17th, 2003, 05:58 AM
CW CW is offline
Authorized User
 
Join Date: Sep 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok. this ís the code.
Table procedure is used. What i want is to dispay some part of retrieved data (eg. Lastname and first name) in hyperlink, while others will not be hyperlinked.
Thanks.

<html>
<head>
<title>Table Procedure</title>
</head>
<body>
<h2>this is the best way of retrieving data by ASAD</h2>
<h3>Make Table Procedure</h3>
<BR>
<h3>First we write the code in the Make Table Procedure</h3>

<%
'Procedure to create a table
sub MakeTable(SourceIn,dsnIn)
dim oRSmt
set oRSmt=server.createobject("ADODB.recordset")
oRSmt.Open SourceIn, "DSN=" & dsnIn
oRSmt.movefirst

response.write "<table border=1><tr>"
For Each Field in oRSmt.Fields
    response.write "<th>" & Field.name & "</th>"
next
'response.end
Do while not oRSmt.EOF
response.write "<tr>"
    For each objField in oRSmt.fields
        response.write "<td>" & objField.value & "&nbsp;</td>"
    Next
    oRSmt.movenext
response.write "</tr>"
loop
response.write "</table>"
oRSmt.close
set oRSmt=nothing
end sub
%> </p>

<h3>one line of code can make a table</h3>
<%call MakeTable("tblComments;","Guest")%></p>


</body>
</html>

Rgds CW



 
Old September 17th, 2003, 06:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Since you are using such a dynamic approach I would recommend that you look in to the .getrows method of the recordset object.

But using the code you have shown here:

Code:
<html>
<head>
<title>Table Procedure</title>
</head>
<body>
<h2>this is the best way of retrieving data by ASAD</h2>
<h3>Make Table Procedure</h3>
<BR>
<h3>First we write the code in the Make Table Procedure</h3>

<%
dim sLinkURL
sLinkURL = "http://www.somehost/somepage.asp?id="

'Procedure to create a table
sub MakeTable(SourceIn,dsnIn)
dim oRSmt
set oRSmt=server.createobject("ADODB.recordset")
oRSmt.Open SourceIn, "DSN=" & dsnIn
oRSmt.movefirst

response.write "<table border=1><tr>"
For Each Field in oRSmt.Fields
    response.write "<th>" & Field.name & "</th>"
next
'response.end
Do while not oRSmt.EOF
response.write "<tr>"
    For each objField in oRSmt.fields
    if lcase(objField.name) = "firstname" or lcase(objField.name) = "lastname" then
        response.write "<td><a href='" & sLinkURL & objField("id") & "'>" & objField.value & "</a>&nbsp;</td>"
    else
        response.write "<td>" & objField.value & "&nbsp;</td>"
    end if
    Next
    oRSmt.movenext
response.write "</tr>"
loop
response.write "</table>"
oRSmt.close
set oRSmt=nothing
end sub
%> </p>

<h3>one line of code can make a table</h3>
<%call MakeTable("tblComments;","Guest")%></p>


</body>
</html>
The code here assumes that you have fields in your recordset named id, firstname and lastname...

 
Old September 17th, 2003, 06:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

I hadn't tested the above code - and now I see a few f**kups ;)

Move the two sLinkURL lines inside the sub - or make sLinkURL PUBLIC.

I'm working on a better version for you...

 
Old September 17th, 2003, 06:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Code:
<%
OPTION EXPLICIT
%>
<html>
<head>
<title>Table Procedure</title>
</head>
<body>
<h2>this is the best way of retrieving data by ASAD</h2>
<h3>Make Table Procedure</h3>
<BR>
<h3>First we write the code in the Make Table Procedure</h3>

<%
'Procedure to create a table
sub MakeTable(SourceIn, dsnIn, sLinkURL, iIdField, sLinkFields)
dim Field, objField, bLinkIt, t
dim aLinkFields
aLinkFields = split(lcase(sLinkFields),",")


dim oRSmt
set oRSmt=server.createobject("ADODB.recordset")
oRSmt.Open SourceIn, "DSN=" & dsnIn
oRSmt.movefirst

response.write "<table border=1><tr>"
For Each Field in oRSmt.Fields
    response.write "<th>" & Field.name & "</th>"
next
'response.end
Do while not oRSmt.EOF
    response.write "<tr>"
    For each objField in oRSmt.fields
        bLinkIt = FALSE
        for t = 0 to ubound(aLinkFields,1)
            if aLinkFields(t) = lcase(objField.name) then
                bLinkIt = TRUE
                exit for
            end if
        next

        if bLinkIt = TRUE then
            response.write "<td><a href='" & sLinkURL & oRSmt.fields(iIdField) & "'>" & objField.value & "</a>&nbsp;</td>"
        else
            response.write "<td>" & objField.value & "&nbsp;</td>"
        end if
    Next
    oRSmt.movenext
    response.write "</tr>"
loop
response.write "</table>"
oRSmt.close
set oRSmt=nothing
end sub
%> </p>

<h3>one line of code can make a table</h3>
<%call MakeTable("SELECT * FROM tbAuthors", "Books", "http://www.somehost/somepage.asp?id=", 0, "AuthorFName,AuthorLName")%></p>


</body>
</html>
I have added a few parametres to your call:
sLinkUrl - the URL you want to link to
iIdField - the index of your id-field
sLinkFields - a commadelimited string of fieldnames that you want to link...

HTH

Jonax






Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink sryap3 Access VBA 1 November 20th, 2008 04:25 PM
How we can use hyperlink nagham Crystal Reports 0 February 9th, 2007 03:51 AM
hyperlink kritimehrotra Excel VBA 3 July 24th, 2006 08:32 PM
hyperlink hyperlink sbhandar Classic ASP Basics 6 August 26th, 2004 02:04 AM
hyperlink pab006 Classic ASP Basics 5 December 17th, 2003 10:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.