...

View Full Version : building links with ASP. HELP!!!



bobjosh
01-12-2005, 05:28 AM
Howdy all,

I am trying to create a link with asp with data being pulled from a database.

The code is below.

Response.Write ("<tr><td align='center'>")
Response.Write "<a href='/images/update_form.asp?IDA=" & rstblstock("Sub_Category")
Response.write "' target='mainFrame'"
response.write " onclick="top.rightFrame.location='/images/related_form.asp?ID=" & rstblstock("Sub_Category")
response.write "";">"
Response.Write ("<font face=Arial size=2>")
Response.Write ("<font color=#9933cc>")
Response.Write "<IMG SRC=" & rstblstock("Image")
Response.Write " border='0' width='95' height='75'>"
Response.Write (rstblstock("sub_category"))
Response.Write ("</font>")
Response.Write ("</a>")
Response.Write ("</td>")
Response.write ("</tr>")

My trouble is that the link won't work due to asp using " and so do my links.

Can anyone please help me.

gwendaal
01-12-2005, 05:56 AM
Sub Link
Dim s
Dim sc,si

sc = rstblstock("Sub_Category")
si = rstblstock("Image")

s = s & "<tr><td align=""center"">"
s = s & "<a href=""/images/update_form.asp?IDA=" & sc & """
s = s & " target=""mainFrame"""
s = s & " onclick=""top.rightFrame.location='/images/related_form.asp?ID=" & sc & "';"">"
s = s & "<font face=""Arial"" size=""2"">"
s = s & "<font color=""#9933cc"">"
s = s & "<img src=""" & si & """
s = s & " border=""0"" width=""95"" height=""75"">"
s = s & sc
s = s & "</font></a></td></tr>"

Response.Write(s)
End sub


CALL Link

bobjosh
01-12-2005, 11:01 PM
gwendaal

Thanks you very much for that.

I have intergrated your code as below:

<html>
<head>
<title>database test</title>
</head>
<body bgcolor="white" text="black">
<table>
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

'Read in the record number to be updated
IngRecordNo = Cstr(Request.QueryString("ID"))

Ingrecordno = "'%" & Ingrecordno & "%'"

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("fpaytons.mdb")

'Create an ADO recordset object
Set rstblstock = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tbl_Stock.Sub_Category, First(tbl_Stock.Image_name) AS [image] FROM tbl_Stock GROUP BY tbl_Stock.Sub_Category Having tbl_Stock.Sub_Category not like " & Ingrecordno & ";"

'Open the recordset with the SQL query
rstblstock.Open strSQL, adoCon

Sub Link
Dim s
Dim sc,si

sc = rstblstock("Sub_Category")
si = rstblstock("Image")

s = s & "<tr><td align=""center"">"
s = s & "<a href=""/images/update_form.asp?IDA=" & sc & """
s = s & " target=""mainFrame"""
s = s & " onclick=""top.rightFrame.location='/images/related_form.asp?ID=" & sc & "';"">"
s = s & "<font face=""Arial"" size=""2"">"
s = s & "<font color=""#9933cc"">"
s = s & "<img src=""" & si & """
s = s & " border=""0"" width=""95"" height=""75"">"
s = s & sc
s = s & "</font></a></td></tr>"

Response.Write(s)
End sub

'Loop through the recordset
Do While not rstblstock.EOF

'Write the HTML to display the current record in the recordset

call link

Loop
'Reset server objects
rstblstock.Close
Set rstblstock = Nothing
Set adoCon = Nothing
%>
</table>
</body>
</html>

Will let you know how it goes. thank you once again for your post.

gwendaal
01-12-2005, 11:06 PM
it will not work in that way

if you want to do so ... then remove >>
Sub Link
End Sub
Call Link

but it's allways better to do a sub or a function and call it where you need it

ghell
01-13-2005, 08:50 AM
in html attributes of tags should ALWAYS be witten in "s.. however asp uses this in a string, so change what you want written as " to ""

ie Response.Write "hello, ""friend"", how are you?"

's should not be used in html attributes and using nothing is also bad
eg:
height=2 <-- wrong
height='2' <-- wrong
height="2" <-- finally :p

so, like, from your original code, change
Response.Write ("<font color=#9933cc>")
to
Response.Write "<font color=""#9933CC"">"

(the parenthesis () does not need to be used with response.write .. since asp3 at least i think)

if you really arent sure about this you couls always close the asptags and reopen them to write a variable like
%>
.... onclick="javascript: top.rightFrame.location='/images/related_form.asp?ID=<%=sc%>';">
<%

gwendaal
01-13-2005, 10:22 AM
s = s & "<font color=""#9933cc"">"

yeeeeeeeeeeeees

bobjosh
01-14-2005, 12:02 AM
Thank you all for your help.

I will implement your recommendations and let you know how i do.

Once again thanks.

josh



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum