Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    building links with ASP. HELP!!!

    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.

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

    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%>';">
    <%

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    s = s & "<font color=""#9933cc"">"

    yeeeeeeeeeeeees

  • #7
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you all for your help.

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

    Once again thanks.

    josh


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •