Forums
This topic is locked
Text to display only if Data in Database Field
Posted 01 Mar 2005 19:26:28
1
has voted
01 Mar 2005 19:26:28 Teresa Pangan posted:
Hi!I have announcements down the left hand column of a site and I need help in how to setup the coding so I display a database field and a space or text only if there is data in the database field.
A common example is you are displaying time and date for a list of activities and have on your page
under each activity description
Date: info from date database field
Time info from time database field
But if no data is in the date and time field, it looks silly to have the text "Date" and "Time" displaying on the page. My scenario is same but using different variables.
I am using Access and ASP/VBScript.
The contact info normally would appear like:
Ron Smith 972-456-7899 email (email address is programmed into the word email)
And if there is nothing in the database, then I want to leave it
blank and take out the space or word email I right now have between the
database fields to try and help positioning (see my coding)
The recordset I am pulling from is rsAnnounce and the database
fields are:
acontact aphone aemail
Here is the coding I am using now and the problem is it inserts the blank spaces even if there is no data in the database field and for email displays the word email even if there is no data in the email field. This is silly! <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
I hope I am making sense to you!!
Thanks for your help!
Healthy regards,
Teresa
<pre id=code><font face=courier size=2 id=code>
<tr>
<td align="left"
valign="top"><p><%=(rsAnnounce.Fields.Item("acontact".Value)%> <%=(rsAnnounce.Fields.Item("aphone".Value)%> <a
href="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>"><font
color="999999">email</font></a></p></td>
</tr>
<tr>
</font id=code></pre id=code>
Edited by - terepan on 01 Mar 2005 19:26:51
Replies
Replied 01 Mar 2005 23:35:58
01 Mar 2005 23:35:58 Wim Conix replied:
Hi Teresa,
You have to use the VBA's IF...THEN...ELSE
Must be something like this :
<tr>
<td align="left"valign="top">
<p>
<%=IF(rsAnnounce.Fields.Item("acontact".Value) <> "" THEN Response.Write (rsAnnounce.Fields.Item("acontact".Value) ELSE Response.Write "" END IF%> <%=IF(rsAnnounce.Fields.Item("aphone".Value) <> "" THEN Response.Write (rsAnnounce.Fields.Item("aphone".Value) ELSE Response.Write "" END IF%> <%=IF (rsAnnounce.Fields.Item("aemail".Value) <> "" THEN%><ahref="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>"><%ELSE Response.Write "" END IF%>
<fontcolor="999999">email
</font>
</a>
</p>
</td>
</tr>
<tr>
I don't know what you want to do with the line <fontcolor="999999">email
I hope this helped you and works the way you want, otherwise let me know...
Wim
You have to use the VBA's IF...THEN...ELSE
Must be something like this :
<tr>
<td align="left"valign="top">
<p>
<%=IF(rsAnnounce.Fields.Item("acontact".Value) <> "" THEN Response.Write (rsAnnounce.Fields.Item("acontact".Value) ELSE Response.Write "" END IF%> <%=IF(rsAnnounce.Fields.Item("aphone".Value) <> "" THEN Response.Write (rsAnnounce.Fields.Item("aphone".Value) ELSE Response.Write "" END IF%> <%=IF (rsAnnounce.Fields.Item("aemail".Value) <> "" THEN%><ahref="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>"><%ELSE Response.Write "" END IF%>
<fontcolor="999999">email
</font>
</a>
</p>
</td>
</tr>
<tr>
I don't know what you want to do with the line <fontcolor="999999">email
I hope this helped you and works the way you want, otherwise let me know...
Wim
Replied 02 Mar 2005 04:47:07
02 Mar 2005 04:47:07 Teresa Pangan replied:
Hi Wim!
Thanks! I am getting closer. But still some kinks.
Here is a test page with the annoucements on the left:
216.97.90.223/discover/indextest.asp
See how the name and telephone number back up to one another.
If there is data, how can I insert a space between the contact name and phone number?
Here is the coding that is bumping up the fields next to one another:
<% IF(rsAnnounce.Fields.Item("acontact".Value)
<> "" THEN Response.Write (rsAnnounce.Fields.Item("acontact"
.Value) ELSE Response.Write "" END IF%>
Then the ASP statement that I could not get to work, aemail (email address).
Here is the coding that is working right now for database fields acontact and aphone:
<pre id=code><font face=courier size=2 id=code>
<% IF(rsAnnounce.Fields.Item("acontact".Value) <>
"" THEN Response.Write (rsAnnounce.Fields.Item("acontact"
.Value) ELSE Response.Write "" END IF%>
</font id=code></pre id=code>
For the email, I have setup that is working but WITHOUT any If Then Response.Write
<pre id=code><font face=courier size=2 id=code>
<a href="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>">
<font color="999999">email</font></a>
</font id=code></pre id=code>
What I need help is writing the If Then Response.Write statement in ASP that first checks if there
is data in the database field aemail (recordset is rsAnnounce) and if so, inserts a space and then
the word email with the data from the database field inserted into the mailto command.
Thanks for your help!!
Edited by - terepan on 02 Mar 2005 04:52:35
Edited by - terepan on 02 Mar 2005 04:53:57
Edited by - terepan on 02 Mar 2005 04:55:26
Thanks! I am getting closer. But still some kinks.
Here is a test page with the annoucements on the left:
216.97.90.223/discover/indextest.asp
See how the name and telephone number back up to one another.
If there is data, how can I insert a space between the contact name and phone number?
Here is the coding that is bumping up the fields next to one another:
<% IF(rsAnnounce.Fields.Item("acontact".Value)
<> "" THEN Response.Write (rsAnnounce.Fields.Item("acontact"
.Value) ELSE Response.Write "" END IF%>
Then the ASP statement that I could not get to work, aemail (email address).
Here is the coding that is working right now for database fields acontact and aphone:
<pre id=code><font face=courier size=2 id=code>
<% IF(rsAnnounce.Fields.Item("acontact".Value) <>
"" THEN Response.Write (rsAnnounce.Fields.Item("acontact"
.Value) ELSE Response.Write "" END IF%>
</font id=code></pre id=code>
For the email, I have setup that is working but WITHOUT any If Then Response.Write
<pre id=code><font face=courier size=2 id=code>
<a href="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>">
<font color="999999">email</font></a>
</font id=code></pre id=code>
What I need help is writing the If Then Response.Write statement in ASP that first checks if there
is data in the database field aemail (recordset is rsAnnounce) and if so, inserts a space and then
the word email with the data from the database field inserted into the mailto command.
Thanks for your help!!
Edited by - terepan on 02 Mar 2005 04:52:35
Edited by - terepan on 02 Mar 2005 04:53:57
Edited by - terepan on 02 Mar 2005 04:55:26
Replied 02 Mar 2005 08:36:10
02 Mar 2005 08:36:10 Dan Berdusco replied:
Hey teresa,
Wim gave you a nice response, but maybe i can help you out a bit more... maybe clarify some stuff (I hope). Try doing your IF statements like this:
<pre id=code><font face=courier size=2 id=code>
<%If NOT (rsAnnounce.Fields.Item("acontact".Value) = "" Then %>
Contact Name: <%=(rsAnnounce.Fields.Item("acontact".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aphone".Value) = "" Then %>
Phone Number: <%=(rsAnnounce.Fields.Item("aphone".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aemail".Value) = "" Then %>
Email Address: <%=(rsAnnounce.Fields.Item("aemail".Value)%> & nbsp;
<% End If %>
</font id=code></pre id=code>
This is very similar to what WIM showed you, but just broken down a bit more. So, it will check each field in the database (contact name, email address, and phone number), it they are empty, then it won't show that information.
To insert a space, i just included a
<pre id=code><font face=courier size=2 id=code>& nbsp;</font id=code></pre id=code> (you will have to take out the space between the & and the nbsp; - if i left it without the space, it wouldn't show up in the post!) that will generate a space.
Hopefully that works for you!
Edited by - flexman44 on 02 Mar 2005 08:38:57
Wim gave you a nice response, but maybe i can help you out a bit more... maybe clarify some stuff (I hope). Try doing your IF statements like this:
<pre id=code><font face=courier size=2 id=code>
<%If NOT (rsAnnounce.Fields.Item("acontact".Value) = "" Then %>
Contact Name: <%=(rsAnnounce.Fields.Item("acontact".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aphone".Value) = "" Then %>
Phone Number: <%=(rsAnnounce.Fields.Item("aphone".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aemail".Value) = "" Then %>
Email Address: <%=(rsAnnounce.Fields.Item("aemail".Value)%> & nbsp;
<% End If %>
</font id=code></pre id=code>
This is very similar to what WIM showed you, but just broken down a bit more. So, it will check each field in the database (contact name, email address, and phone number), it they are empty, then it won't show that information.
To insert a space, i just included a
<pre id=code><font face=courier size=2 id=code>& nbsp;</font id=code></pre id=code> (you will have to take out the space between the & and the nbsp; - if i left it without the space, it wouldn't show up in the post!) that will generate a space.
Hopefully that works for you!
Edited by - flexman44 on 02 Mar 2005 08:38:57
Replied 02 Mar 2005 19:34:50
02 Mar 2005 19:34:50 Teresa Pangan replied:
Hi Trevor!
Thanks a bunch! It worked.
Here is what I ended up using:
<%If NOT (rsAnnounce.Fields.Item("acontact".Value) = "" Then %>
Contact Name: <br>
<%=(rsAnnounce.Fields.Item("acontact".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aphone".Value) = "" Then %>
<br>
Phone: <%=(rsAnnounce.Fields.Item("aphone".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aemail".Value) = "" Then %>
<a href="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>">Email Address</a> & nbsp;
<% End If %>
If you are reading the coding I did program in the space (& nbsp) with an extra space so it would
show up on the posting like Trevor mentioned. If you use it, take out the space.
It only shows the word Contact Name, or Phone or Email with the space if it has data in the database
field. If there is no data, it moves on to the next database field request.
Worked perfect!!
Thanks again.
Healthy regards,
Teresa
Thanks a bunch! It worked.
Here is what I ended up using:
<%If NOT (rsAnnounce.Fields.Item("acontact".Value) = "" Then %>
Contact Name: <br>
<%=(rsAnnounce.Fields.Item("acontact".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aphone".Value) = "" Then %>
<br>
Phone: <%=(rsAnnounce.Fields.Item("aphone".Value)%> & nbsp;
<% End If %>
<%If NOT (rsAnnounce.Fields.Item("aemail".Value) = "" Then %>
<a href="mailto:<%=(rsAnnounce.Fields.Item("aemail".Value)%>">Email Address</a> & nbsp;
<% End If %>
If you are reading the coding I did program in the space (& nbsp) with an extra space so it would
show up on the posting like Trevor mentioned. If you use it, take out the space.
It only shows the word Contact Name, or Phone or Email with the space if it has data in the database
field. If there is no data, it moves on to the next database field request.
Worked perfect!!
Thanks again.
Healthy regards,
Teresa