Click to See Complete Forum and Search --> : create dynamic hyperlink from database field
blodefood
10-20-2003, 10:12 AM
I would like to create a page of hyperlinks that are constructed from the contents of a database field. When the user clicks the link they are taken to a page that will display all fields from that particular record.
I already have the page structures in place. There are two pages, one with the links and the other to display the record.
I have this so far.
<a href="<%response.write rs.Fields("JobDescName")%>"><%response.write rs.Fields("JobDescName")%></a>
The hyperlink would say something like:
Supervisor - Widget Department.
The page it would go to is
http://..../JobDescription.asp(whatever code is necessary to pull the fields from that record).
Any help would be appreciated.
Thanks,
blodefood
simflex
10-20-2003, 01:15 PM
let me make sure I understand you.
Your first page will contain a link (linked record from the db).
Once you click on that record, it opens up a detailed records about that linked record, right?
If so, here you go.
This is done in a hurry so forgive any bugs.
I am calling page1 listRecs.asp
<%
set my_conn= Server.CreateObject("ADODB.Connection")
myDSN="DSN=YourDSN"
'response.write mydsn
'response.end
my_Conn.Open myDSN
SQL = "SELECT * FROM YourTable"
set RS = my_conn.execute(SQL)
%>
<HTML>
<HEAD>
<TITLE>View Accidents</TITLE>
</HEAD>
<BODY>
<font size="+3" face="arial">Name - Description</font><hr>
<ul>
<%
Do While NOT RS.EOF
%>
<li> <a href="PullRecs.asp?ID=<%=RS("JobDescName")%>"> -
<%=RS("JobDescName")%></a><br>
<%
RS.Movenext
loop
%>
</ul>
</BODY>
</HTML>
and page2 PullRecs.asp
<%
dim strsql,ID
set my_conn= Server.CreateObject("ADODB.Connection")
myDSN="DSN=YourDSN"
'response.write mydsn
'response.end
my_Conn.Open myDSN
trackingNumber = request.querystring("ID")
strsql= "SELECT FROM YOUR TABLE WHERE ID ="&ID 'assuming id is an int
set rs = my_conn.Execute (StrSql)
'response.write("strsql")
'response.end
if rs.BOF or rs.EOF then ' No records found
response.write "Hmm... That didn't work.<br>There was an error. Oh well, try again.<a href=javascript:history.back();>back</a>"
response.end
end if
%>
<body>
<form method="POST" action="PullRecs.asp"">
<table border="1" cellpadding="0" cellspacing="0" width="86%" border="2">
<tr>
<TD>name</TD>
<td> input type=text name="firstInfo" size="25" value="<%=rs("firstRecordFromDB")%>">
</TD>
</TR>
<tr>
<td bgcolor="ffffff"><form method="POST" action="PullRecs.asp"">
<TD>name</TD>
<td> input type=text name="SecondInfo" size="25" value="<%=rs("SecondRecordFromDB")%>">
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE=BUTTON VALUE="Next Record" onClick="location='ListRecs.asp'">
</TD>
</TR>
</TABLE>
</form>
</body>
</html>
blodefood
10-20-2003, 03:17 PM
Thanks. The links work now. I hope it will help me sort out some bugs in the other page.
Fortunately, this is not a rush project, but it is ongoing, so I will be back for more later.
Thanks again.
blodefood.
;)
coolafgz
02-15-2009, 02:28 AM
I know it has been awhile on this post but I really need help with page2 PullRecs.asp. No matter what I do, I can't fix the bug. Can someone help me please..