PDA

View Full Version : Formatting data from a database into an HTML page


pthompson2002
10-01-2002, 09:35 AM
I would like to display data that the user retrieves from a database in an HTML page. However as the data is just one long line of text in the database I would like to add formatting to it when it is displayed.
Is there a way I can insert html formatting tags into the data I am retrieving before it is displayed on the HTML page?

glenngv
10-01-2002, 09:40 AM
up to what extent you want the formatting done? like making some text bold, some italics...?

Alekz
10-01-2002, 09:42 AM
Hi,
Yes, You can insert HTML formatting tags in a string... Split the string in locations where You have to insert HTML tags, then concatenate string parts with HTML formatting tags and then output the result... OK? Can You be more concrete?

Alex

pthompson2002
10-01-2002, 09:45 AM
I'll try and be more specific....

The data is basically text, like a message up to 2000 characters long. Therefore I would like to basically just add in <p> tags so it is not displayed as one big line of text. It may be simple to do but I haven't really got any idea where to start looking, I'm not sure if it is a JavaScript problem or ASP.

glenngv
10-01-2002, 09:59 AM
is the text really in just one line? or it has line breaks?
If the latter, you can do this:

response.write "<pre>" & str & "</pre>"

change str to your variable

if the former, you can put the text in a table cell without nowrap attribute so that it goes to the next line if it doesnt fit in the cell:

<table>
<tr>
<td width=100>
<%=str%>
</td>
</tr>
</table>

Alekz
10-01-2002, 10:00 AM
Hi,
If You are using a TEXTAREA to input the message, try when outputting it through Response.Write do something like this:

Response.Write(Replace(Msg,vbCrLf,"<br>"))

This will replace line breaks generated by TEXTAREA with HTML line breaks... Just to start...

Alex

biggs27
10-21-2002, 05:10 PM
To expand on Alekz's suggestion, try the following. This will read just about any HTML tag. Bold, italic, underline, br, even hyperlink, and display it accordingly.

<%
Function HTML (GetTheStr)
Start = 1
whereis = 1
NewHTMLStringWithBreaks = ""
RemaindingHTMLString = GetTheStr
RemaindingHTMLString = RemaindingHTMLString & chr(13)
do until (whereis = 0)
Whereis = InStr (1, RemaindingHTMLString, Chr(13))
Chr13Position = Whereis - 1
LineOfHTMLBeforeNextChr13 = Mid(RemaindingHTMLString, 1 , Whereis)
Chr13Position = Whereis + 2
LineOfHTMLAfterNextChr13 = Mid(RemaindingHTMLString, Chr13Position, Len(RemaindingHTMLString))
RemaindingHTMLString = LineOfHTMLAfterNextChr13
NewHTMLStringWithBreaks = NewHTMLStringWithBreaks & LineOfHTMLBeforeNextChr13 & "<br>"
loop
HTML = NewHTMLStringWithBreaks
End Function
%>

I use the following to output:

<%=HTML(rs("field"))%>

pthompson2002
10-22-2002, 08:55 AM
thanks, I should of closed this thread. I managed to fix it. Thanks for everyones help