...

View Full Version : Checking Fields in a database



Crash1hd
02-05-2003, 10:51 AM
I was wondering how would I go about doing the following in asp

here is the code example what I want to do

If RS("HttpLink") <>"" Then
If RS("HttpLink") contains "Http" Then
response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
End If
If RS("HttpLink") does not contain "Http" Then
response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
End If
End If

Changing the Contains and Does not contain to actual vbscript or asp script characters!

Basically the httplink field will contain web addresses and some may contain the http:// header and some may not but when the dont and I dont add the http:// then the link doesnt work on the page!

Any thoughts :)

arnyinc
02-05-2003, 01:39 PM
Assuming the links will be in either of these two forms:

www.codingforums.com
http://www.codingforums.com

It is sufficient to just test the left four character to make sure they are "http". I converted them to lowercase so that it matches any case the user might enter (http, HTTP, Http, etc.)


<%
If RS("HttpLink") <>"" Then
If lcase(left(RS("HttpLink")))="http" Then
response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
else
response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
End If
End If
%>

raven
02-05-2003, 01:42 PM
I'd do this:

strLink = Replace(RS("httpLink"),"http://","")

response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"

This will remove all instances of http:// and replace with nothing.

It might be better to use a simple function though, like this:

Function removeHTTP(link)

cleanLink = Replace(link,"http://","")
cleanLink = Replace(cleanLink,"http:/","")

{insert more here to replace any other possible misspellings of http://}

removeHTTP = cleanLink

End function

The you would write to the page as:

response.write "<P ALign=Center><a href=http://" & removeHTTP(RS.fields("HttpLink")) & " target=blank_>Click Here</a>"

Crash1hd
02-06-2003, 09:36 AM
Thankyou both for all the choices I will say that the only one that worked was the function one at the end so I am glad you added it the other 2 both of yours returned the following on the link
http://φֳ/

Aarnyinc yours returned the following first but i fixed that


Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'left'

/Obituarys/Viewing_Obituary.asp, line 116

but the fix was the following


<%
If RS("HttpLink") <>"" Then
If lcase(left(RS("HttpLink"), http)) Then
response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
else
response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
End If
End If
%>

but after i fixed it then i got the following above as i did with ravens first one not sure why thought!!!

But dont get me wrong I am very thankfull for any support given and I just want to say thankyou :)

P.s. I must be getting better at this as I was able to find the mistake and fix it without any help :) Yeah me :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum