473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Asp eliminating blank lines in database listing

I'm a newbie to ASP and databases. I have created a simple contact list database and an asp page that shows the contact listing. So far so good.

Here's what I have:
Expand|Select|Wrap|Line Numbers
  1. <%=rs.fields("CompanyName")%> <BR>
  2. <%=rs.fields("FirstName")%>&nbsp;<%=rs.fields("LastName")%> <BR>
  3. <%=rs.fields("Title")%> <BR>
  4. <%=rs.fields("Address")%> <BR>
  5. <%=rs.fields("Address2")%>  <BR>
  6. <%=rs.fields("Address3")%>  <BR>
  7. <%=rs.fields("Country")%>  <BR>
  8. <%=rs.fields("City")%> <%=rs.fields("State")%> <%=rs.fields("Zip")%> <BR>
  9. <%=rs.fields("State")%>  <BR>
  10. <%=rs.fields("Zip")%> <BR>
  11. Tel:&nbsp;<%=rs.fields("WorkPhone")%> &nbsp;or&nbsp;<%=rs.fields("WorkPhone2")%> <BR>
  12. Mobile:&nbsp;<%=rs.fields("MobilePhone")%> <BR>
  13. Fax:&nbsp;<%=rs.fields("FaxNumber")%> Email:&nbsp;<a href="mailto:<%=rs.fields("EmailName")%>"><%=rs.fields("EmailName")%></a><BR>
  14.  
The problem I have is that I want to skip the field altogether if there is no data in that field. This is the kind of result that I am trying to clean up:

Coburn Graphic Films, Incorporating.


1650 Corporate Road West



Lakewood NJ 08701
NJ
08701
Tel: 404-656-3855 or
Mobile: 404-656-3856
Fax: 404-656-7916 Email: gach@opb.state.ga.us

I guess I need and if, then, else statement to skip the blanks, but I don't know how to do it. Can anyone help?

Thanks!

-S
Aug 30 '07 #1
8 1798
ilearneditonline
130 Expert 100+
You will need to check if they exist first....

Expand|Select|Wrap|Line Numbers
  1.  <% if LEN(rs.fields("Zip")) > 0 then 
  2. Response.Write(rs.fields("Zip")
  3. end if%>
  4.  
Or you could write a function to handle this.
Expand|Select|Wrap|Line Numbers
  1.  function valueExists(input){ 
  2. if LEN(input) > 0 then
  3. Response.Write(input)
  4. end if
  5. }
  6.  
  7. ' call the function
  8. valueExists(rs.fields("Zip")) 
  9.  
Aug 30 '07 #2
Thanks for your reply. I believe your If statement will check to see if the field is greater than 0 and if so it displays the field. What I'm trying to do is a little bit more than that. If the field is greater than 0 then I would like to add some formatting code as well such as a label, the database field and then a break. So I'm looking to say this:

If the address field is greater than zero then type:
"Address: - <display field contents> <BR>"

Can you expand on your answer? Thanks!
Aug 30 '07 #3
ilearneditonline
130 Expert 100+
Thanks for your reply. I believe your If statement will check to see if the field is greater than 0 and if so it displays the field. What I'm trying to do is a little bit more than that. If the field is greater than 0 then I would like to add some formatting code as well such as a label, the database field and then a break. So I'm looking to say this:

If the address field is greater than zero then type:
"Address: - <display field contents> <BR>"

Can you expand on your answer? Thanks!
Expand|Select|Wrap|Line Numbers
  1.  function valueExists(input, formatbegin, formatend){ 
  2.   if LEN(input) > 0 then
  3.     Response.Write(formatbegin & input & formatend)
  4. end if
  5. }
  6.  
  7. ' call the function
  8. valueExists(rs.fields("Zip"), "Zip Code: ","<br />") 
  9.  
Aug 30 '07 #4
Sadly I am too inexperienced to put your suggested into use. I'm flailing over here trying to get this to work. Is there any assistance you can offer? It seems a simple business, but I'm obviously missing something. I'd be happy to pay you to write this page for me.

Thanks!

-Tracy
Aug 30 '07 #5
markrawlingson
346 Expert 100+
Tracy,

Here's your example... Which will simply display everything, including fields which have no value.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%=rs.fields("CompanyName")%> <BR>
  3. <%=rs.fields("FirstName")%>&nbsp;<%=rs.fields("LastName")%> <BR>
  4. <%=rs.fields("Title")%> <BR>
  5. <%=rs.fields("Address")%> <BR>
  6. <%=rs.fields("Address2")%> <BR>
  7. <%=rs.fields("Address3")%> <BR>
  8. <%=rs.fields("Country")%> <BR>
  9. <%=rs.fields("City")%> <%=rs.fields("State")%> <%=rs.fields("Zip")%> <BR>
  10. <%=rs.fields("State")%> <BR>
  11. <%=rs.fields("Zip")%> <BR>
  12. Tel:&nbsp;<%=rs.fields("WorkPhone")%> &nbsp;or&nbsp;<%=rs.fields("WorkPhone2")%>
  13.  
  14.  
What he's suggesting that you do is have your code check to see if a field is empty before displaying it - such as the below...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. If LEN(rs.fields("CompanyName")) > 0 Then 
  3.      Response.Write "Company Name: " & rs.fields("CompanyName")
  4. End If
  5.  
In other words... If there is even 1 character in "CompanyName" - it will be displayed, if not, it will not be displayed. You can format it however you like.
Aug 30 '07 #6
jhardman
3,406 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. <%
  2. If LEN(rs.fields("CompanyName")) > 0 Then 
  3.      Response.Write "Company Name: " & rs.fields("CompanyName")
  4. End If
  5.  
In other words... If there is even 1 character in "CompanyName" - it will be displayed, if not, it will not be displayed. You can format it however you like.
I usually do something more like:
Expand|Select|Wrap|Line Numbers
  1. for each x in rs.fields
  2.    if trim(rs(x)) <> "" then response.write x & ": " & rs(x) & "<br>" & vbNewLine
  3. next
this will print out every field (if it isn't empty). If a user inputs a space in an input, the script might interpret this as important and save it to the db, in which case you do have a value: " ". My method will eliminate those as well. Of course, it is a good idea to trim every input right before you save it...

Jared
Aug 30 '07 #7
markrawlingson
346 Expert 100+
That's a really good way of doing it actually.. that will totally elimate your problem Tracy.

I'm going to adapt this method in my own work, Jared. Never thought of doing it that way before.

Mark
Aug 30 '07 #8
Genius! Even I understood that. Thank you so much!!
Aug 31 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MX1 | last post by:
Hi, I have a report with Name1 and Name2 in the address section . Sometimes, Name2 is not populated with data via the query that feeds the report. Unfortunately, the blank line stays in the...
28
by: Steve Jorgensen | last post by:
I often come up with logic like this somewhere in a function: .... If Not IsNull(<some expression>) Then <default action> Else <alternative action> End If ....
6
by: Melissa | last post by:
Does anyone have a generic procedure for adding blank lines to reports like Sales details, PO details and/or Orders details. The procedure would need to count the number of line items, determine...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
3
by: BradC | last post by:
I have a big VS 2002/2003 annoyance, and wondering if there is a way to turn it off: Put your cursor at the start of an indented line of code inside a function. (right before the first...
2
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the...
5
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
3
by: ShaeMills via AccessMonster.com | last post by:
In my table I imported from .txt, one of my columns has blank spaces. The column is as follows, how do I eliminate the blank spaces in between the second and third, and fifth and sixth digits? ...
5
by: MLH | last post by:
I'm using A97 import data wizard to import text file N2 a table. The text file is a DIR listing produced by running dir jdc*.* /s c:\JDCs.txt The wizard is chopping the lines off at the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.