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> </td>"
else
response.write "<td>" & objField.value & " </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