1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can't show URL from database

Discussion in 'C#' started by minciamia, Mar 26, 2008.

  1. #1
    Hi :)
    Here's my problem: in a page wich should show a clickable url, i can't show the URL itselfs; all i'm able to do is to show an alternate test like "visit".
    But i'd need to show the url especially because in some records the url is missing, so if i'll manage to fix the problem, the result should be to show the url if available, and to show nothing if not available.

    Here's the code:
    
    <% Option Explicit %>
    <!--#include file="common.asp" -->
    <%
    
    
    Dim rsNews	'Database recordset holding the news items
    Dim rsComments	'Database recordset holding the comments for this news item
    Dim lngNewsID	'Holds the News item ID number
    Dim blnComments	'Set to true if comments are allowed for this item
    
    'Read in the ID number of the news item we are looking at the comments of
    If isNull(Request.QueryString("NewsID")) = True Or isNumeric(Request.QueryString("NewsID")) = False Then
    	Response.Write "default.asp"
    Else
    	lngNewsID = CLng(Request.QueryString("NewsID"))
    	
    End If
    %>
    
    
     <%
    
    'Create recorset object
    Set rsNews = Server.CreateObject("ADODB.Recordset")
    	
    'Initalise the strSQL variable with an SQL statement to query the database by selecting all tables ordered by the decending date
    strSQL = "SELECT tblNews.* FROM tblNews WHERE tblNews.ID = " & lngNewsID & " ORDER BY ID ASC;"
    	
    'Query the database
    rsNews.Open strSQL, adoCon
    
    
    'If there are no records then exit for loop
    If NOT rsNews.EOF Then
    	
    	'Read in if comments are allowed for this news item
    	blnComments = CBool(rsNews("Comments"))
    	
    	%>
    working:
    [COLOR="SeaGreen"]<a target="_blank" href="<% = rsNews("url") %>">- Visit </a>[/COLOR]
    
    not working:
    [COLOR="Red"]<a target="_blank" href="<% = rsNews("url") %>"><% = rsNews("url") %></a>[/COLOR]
    
    
    Code (markup):
    I'm sure that there must be some way to fix it, but i'm unable to find it out.
    Please, someone any ideas? :confused: (edit: spelling)
     
    minciamia, Mar 26, 2008 IP
  2. kadesmith

    kadesmith Peon

    Messages:
    479
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know if this would work, but try assigning the rs value to a string and then use the string as the URL in the href.

    strURL = rsNews("url")

    <a target="_blank" href="<%=strURL%>"><%=strURL%></a>

    Don't know why that would make any difference though?
     
    kadesmith, Mar 29, 2008 IP
  3. NadeemJaz

    NadeemJaz Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    imo best thing would be to build the link then output it


    <%
    linkVal = "<a target='_blank' href='" & rsNews("url") & "'> " & rsNews("url") & "</a>"
    %>

    <%=linkVal%>
     
    NadeemJaz, Mar 30, 2008 IP
  4. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    urlencode may required for href
     
    JJnacy, Mar 30, 2008 IP