Google Answers Logo
View Question
 
Q: ASP - Database - Process HTML from the database ( Answered 4 out of 5 stars,   0 Comments )
Question  
Subject: ASP - Database - Process HTML from the database
Category: Computers > Programming
Asked by: webdesignguy-ga
List Price: $7.50
Posted: 05 Jun 2003 14:17 PDT
Expires: 05 Jul 2003 14:17 PDT
Question ID: 213601
I have a SQL database that I am grabbing data from using Frontpage 
2002.  Not the best approach, but it will do if I can just get one 
little thing to work. 
 
I can search the database and query the data just fine - the DSN is 
set etc. 
 
I can easily link from the preliminary search results to a detail page
which shows more detail on each product. 
 
Problem:  In the database, I have a couple of fields that contain HTML
and I can't seem to figure out how to get it to process the HTML from
these fields after it pulls it from the database. 
 
It will pull it out just fine, but it then displays it as text, rather
than processing the HTML.  I figure it is something easy like changing
it to a response.write to get it to process the HTML rather than just
spit it out as text. For example, if I have the following in a field
"<b>Test of HTML</b>", it comes out as "<b>Test of HTML</b>", rather
than putting the 3 words in bold.
 
The second part of the problem is that Frontpage gets a bit testy 
about changing the results of the database results wizard.  I tried to
get around that by editing the page in notepad.  I might be getting 
close but no matter what I have tried it still won't process the HTML
from that field. 

Any suggestions?

Best regards,

WebDesignGuy

Request for Question Clarification by hailstorm-ga on 05 Jun 2003 22:58 PDT
webdesignguy,

Are you placing the results within <%= ... %> delimiters?  For
example, this simple ASP code:

<%
testvar = "<B>Test HTML</B>"
%>

<%=testvar%>

Should result in the message "Test HTML" from the variable testvar
appearing in bold when viewed on your browser.  Could you verify that
this is happening?

Clarification of Question by webdesignguy-ga on 06 Jun 2003 07:04 PDT
Hi, Thanks for your help.

First of all, I had forgot to add in this bit of code (inside the
Front Page database results coding).

<%
   strLink = FP_FieldLink(fp_rs,"Link") 
   Response.Write strLink             
%>


This is getting me closer, now it comes out in bold, but I get the
following:


Test%20of%20HTML


It is probably one of those dumb things that I forgot.  Any
suggestions?

Thanks,

WebDesignGuy
Answer  
Subject: Re: ASP - Database - Process HTML from the database
Answered By: dewolfe001-ga on 14 Jun 2003 23:47 PDT
Rated:4 out of 5 stars
 
<% 
Private Function URLDecode(byVal encodedstring)
   Dim strIn, strOut, intPos, strLeft
   Dim strRight, intLoop
   strIn  = encodedstring : strOut = _
     "" : intPos = Instr(strIn, "+")
   Do While intPos
      strLeft = "" : strRight = ""
      If intPos > 1 then _
         strLeft = Left(strIn, intPos - 1)
      If intPos < len(strIn) Then strRight = Mid(strIn, intPos + 1)
      strIn = strLeft & " " & strRight
      intPos = InStr(strIn, "+")
      intLoop = intLoop + 1
   Loop
   intPos = InStr(strIn, "%")
   Do while intPos
      If intPos > 1 Then strOut = strOut & Left(strIn, intPos - 1)
      strOut = strOut & Chr(CInt("&H" & mid(strIn, intPos + 1, 2)))
      If intPos > (len(strIn)-3) then
         strIn = ""
      Else
         strIn = Mid(strIn, intPos + 3)
      End If
      intPos = InStr(strIn, "%")
   Loop
   URLDecode = strOut & strIn
End Function

strLink = FP_FieldLink(fp_rs,"Link")  
Response.Write URLDecode(strLink)              
%>

Request for Answer Clarification by webdesignguy-ga on 16 Jun 2003 15:33 PDT
Wow, that's quite a chunk of code to get this to work.  It appears
that you are trying to isolate and eliminate the % sign from the
results.  This would solve the immediate issue, but unless I'm missing
something, it would not solve the larger issue.

Perhaps I am very much mistaken, but isn't there an easy way to grab
HTML (of all sorts) from a database field and then not only display
it, but to send it to the HTML stream as HTML, rather than as text.

For example, what happens if I want to include <BR>, links etc.  Is
there some small thing that I can do to make the HTML be processed
that is found in the database?  I know I have seen this done before in
other shopping cart software programs.

Thanks for any additional help.

Best regards,

WebDesignGuy

Clarification of Answer by dewolfe001-ga on 16 Jun 2003 17:05 PDT
I think I'm missing something. Can you answer this "clarification"?

HTML from a database field will look like this in the database:

<br>
Test <b>test</b> <i>Test</i>
<br>

When it's included in the ASP output, it will become part of the HTML
that gets output to the client.

If you want to instead have the HTML end up coming to client as source
code, you can do this:

Response.Write(Server.HTMLEncode(strLink))

Server.HTMLEncode will convert the HTML into &gt; and &lt; and other
symbols. The finished output will look like raw HTML, while the actual
HTML code will look very different.
webdesignguy-ga rated this answer:4 out of 5 stars
Found the dumb mistake that I made.  Thanks for your help.

Best regards,

WebDesignGuy

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy