PDA

View Full Version : write rows not columns or add line break after non-empy recordset


saljb
06-21-2005, 09:28 PM
I have colums in my table named feature1, feature2, feature3, etc....
I would like to write them in my asp document with a line break in between them. I did this:

<%Response.Write Recordset("feature1")%>
<br />
<%Response.Write Recordset("feature2")%>
<br />
<%Response.Write Recordset("feature3")%>
<br />
<%Response.Write Recordset("feature4")%>
<br />
<%Response.Write Recordset("feature5")%>
<br />
<%Response.Write Recordset("feature6")%>
<br />
<%Response.Write Recordset("feature7")%>


But then if one of the recordsets are empty there will be an unnecessary line break. So then I tried this:

<%
dim features
features = (Recordset("feature1") & Recordset("feature2") & Recordset("feature3") & Recordset("feature4") & Recordset("feature5") & Recordset("feature6") & Recordset("feature7"))
%>
<%=features%>


But then they are right next to each other.

How can I write the code so that a line break is inserted after each non-empty recordset

or is there a way to write the row (not the column) from the access database and choose which fields to display (I will assume by column name)

e.g. I would want to display only fields from Row name1 but only those fields under Column Name2 thru Column Name4

Col Name 1 |Col Name 2 |Col Name 3 |Col Name 4 |
Row Name1 |Row Name1 |Row Name1 |Row Name1 |
Row Name2 |Row Name2 |Row Name2 |Row Name2 |
Row Name3 |Row Name3 |Row Name3 |Row Name3 |
Row Name4 |Row Name4 |Row Name4 |Row Name4 |

what is the most efficient method for what I am looking for?

Thanks.SalJB

glenngv
06-22-2005, 04:43 AM
<%
dim index, feature
for index = 1 to 7
feature = Recordset("feature" & index)
if not isnull(feature) and feature<>"" then
Response.Write feature & "<br />" & vbCrLf
end if
next
%>

saljb
06-22-2005, 03:46 PM
Thanks this works perfectly could you explain
vbCrLf I know it means "Carriage Return and Line Feed" but I would appreciate an explanation and what instances that would be used.

If all fields are empty how can I write something like "n/a"

I tried this:


<%
dim index, feature
for index = 1 to 7
feature = Recordset("feature" & index)
if not isnull(feature) and feature <> "" then
Response.Write feature & "<br />" & vbCrLf
Else Response.Write "n/a"
end if
next
%>

But that just wrote n/a in the empty fields. I want if all fields are empty to write n/a.

Thank you.SalJB

saljb
06-22-2005, 10:13 PM
Got it. (werD from aspFree contributed to solution)


<%
dim index, feature
i=1
for index = 1 to 7
feature = Recordset("feature" & index)
if not isnull(feature) and feature <> "" then
Response.Write feature & "<br />" & vbCrLf
Else
Response.Write ""
i=i+1
If i > 7 Then
Response.Write"N/A"
end if
end if
next
%>


thanks.SalJB

glenngv
06-23-2005, 03:10 AM
Thanks this works perfectly could you explain
vbCrLf I know it means "Carriage Return and Line Feed" but I would appreciate an explanation and what instances that would be used.

I put vbCrLf to put new line in the HTML source. So that when you View-Source the page, the HTML code is easier to read and debug. It has no effect when the browser renders it (unless you enclose it in <pre> tag where the whitespaces are preserved). It's just there to make the HTML source generated look good.