View Full Version : Database hyperlinks
Dingbat
01-11-2003, 01:29 PM
Hi Guys,
After finally getting a database to work on an intranet I need your further assistance.
I need from a result page generated with a search to be able to open another page that refers to the particular record. I need to know where to insert the <a> tag?
Any assistance is greatly appreciated.
The Dingbat:confused:
bostjank
01-11-2003, 01:50 PM
Hi!
What you need to do is to create a hyperlink with a querystring that points to a certain record (ID is best)
For example: if you have a list of names retireved from database, retireve ID as well and use it in querystring
...
sSQL = "SELECT ID, Name FROM names WHERE ..."
set rs = conn.Execute(sSQL)
Do While Not rs.EOF
Response.Write "<a href=""detail.asp.id=" & rs(0) & """>" & rs(1) & "</a><br>"
rs.MoveNext
Loop
Then, on detail.asp you catch querystring value and then display detailed values.
Hope it helps,
Bostjan
Gavric
09-07-2005, 01:02 AM
I, too, am looking to accomplish this feat. However, I'm not sure from your code snippet exactly what you're doing. Can you be more verbose?
Specifically:
What values are the rs(0) and rs(1) related to?
I know that "rs" is used to mean Record Set, but I'm not sure what the numbers refer to (I'm very new to ASP).
Can you be more specific about the coding of "detail.asp"?
Any assistance is greatly appreciated.
miranda
09-07-2005, 02:41 AM
another way to do this is to use the names of the fields instead of the placeholder
sSQL = "SELECT ID, Name FROM names WHERE ..."
set rs = conn.Execute(sSQL)
Do While Not rs.EOF
Response.Write "<a href=""detail.asp?id=" & rs("id") & """>" & rs("name") & "</a><br>"
rs.MoveNext
Loop
0 is the id placeholder
1 is the name placeholder
Gavric
09-07-2005, 05:43 AM
Okay...so now what's wrong with my SQL string?!?!
I hate programming. : (
<%@ LANGUAGE="JavaScript"%>
<HTML>
<HEAD>
<%
var Record = new String(Request.QueryString("Entry"))
var DBConn = Server.CreateObject("ADODB.Connection")
var Update = Server.CreateObject("ADODB.Recordset")
var UQuery = "SELECT Helpdesk, Subject, Update, Affected, Actions, Info, UserID, PDate, PTime FROM UpdateData WHERE (((Entry)='14'));"
DBConn.Open(Application("HDNewsConnStr"))
Update.Open(UQuery, DBConn)
%>
<LINK REL="stylesheet" TYPE="text/css" HREF="infinet.css">
<TITLE><%Response.Write(Update("Subject"))%></TITLE>
</HEAD>
<BODY>
<TABLE WIDTH="100%" STYLE="margin: 0px, 100px">
<TR>
<TD>
<H3 CLASS="header"><%Response.Write(Update("Subject"))%></H3>
<H6 CLASS="content"><B>Description:</B><BR>
<%Response.Write(Update("Update"))%><BR><BR>
<B>Affected Users:</B><BR>
<%Response.Write(Update("Affected"))%><BR><BR>
<B>Action To Take:</B><BR>
<%Response.Write(Update("Actions"))%><BR><BR>
<B>Additional Information:</B><BR>
<%Response.Write(Update("Info"))%></H6>
<H5 STYLE="text-align: center"><B>Posted By:</B> <%Response.Write(Update("UserID"))%><BR>
<%Response.Write(Update("PDate"))%> @ <%Response.Write(Update("PTime"))%></H5><BR>
</TD></TR>
</TABLE>
</BODY>
</HTML>
This is the "detail.asp" file I sent the data to. I was having no luck passing the querystring value to the SQL query, so I just filled it with an entry number to test my page...and I get, "Data type mismatch in criteria expression.
/HlpDskUpdt/update.asp, line 10"
miranda
09-07-2005, 12:27 PM
Okay...so now what's wrong with my SQL string?!?!
var UQuery = "SELECT Helpdesk, Subject, Update, Affected, Actions, Info, UserID, PDate, PTime FROM UpdateData WHERE (((Entry)='14'));"
Entry is a numeric field, therefore you do not enclose the search for value in single quotes. try this instead
var UQuery = "SELECT Helpdesk, Subject, Update, Affected, Actions, Info, UserID, PDate, PTime FROM UpdateData WHERE Entry=14;"
to search for a variable x do so like this
var x = request.querystring("entry");
var UQuery = "SELECT Helpdesk, Subject, Update, Affected, Actions, Info, UserID, PDate, PTime FROM UpdateData WHERE Entry="+ x + ";";
neocool00
09-07-2005, 01:12 PM
Also, not sure what database you are using on the backend, but "Update" is a keyword in most (if not all), therefore you should put brackets around it like this:
var UQuery = "SELECT Helpdesk, Subject, [Update], Affected, Actions, Info, UserID, PDate, PTime FROM UpdateData WHERE Entry=14;"
Gavric
09-08-2005, 03:51 AM
FANTASTIC!!!
Brilliant. Thanks, again, to one and all. My page is 98% complete and I couldn't have done it without the help of these forums. I just wish I could share the results with all of you. Alas, they're behind the firewall.
From the lessons I've learned here I've slimmed my code down and have even begun spicing up my personal site.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.