By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

help with asp classic if else loop

100+
P: 120
hi guys

im having trouble with my asp if else loop. I'm very close but not 100% quite there yet.

in my sql server table I have flight routes which consist of prices, dates, months - I am then pulling this out using classic asp on my site

what i want is
1. if all 5 prices are NULL to not display anything.
2. and only display rows that have a price. e.g I wouldnt want to display row 1 & 4 by looking at the same data below. so in the sample data's case just to skip row 1 and row 4.

sample data
Expand|Select|Wrap|Line Numbers
  1. GATWICK to TORONTO
  2. Price     Flight Date/s
  3. 219     Dec 7
  4. 149     Jan 13, 14, 16, 20, 21, 23
  5. 179     Feb 3, 4, 6, 10, 11, 13, 17, 18, 24, 25, 27
  6.                                                   
in my asp logic I can skip the first row, display the next 3 rows and skip the 4th row - see below
Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'DISPLAY PRICES
  3. DIM objConn1
  4. Set objConn1 = Server.CreateObject("ADODB.Connection")
  5. objConn1.ConnectionString = "Provider=SQLOLEDB;Data Source=IPREMOVED" & _
  6. "Initial Catalog=DBNAMEREMOVED;User ID=IDREMOVED;Password=PASSWORDREMOVED"
  7. objConn1.Open
  8.  
  9. DIM FLIGHTROUTE1
  10. FLIGHTROUTE1 = "SELECT * FROM UK_Specials WHERE ID = 1"
  11.  
  12. DIM objRS1
  13. Set objRS1 = Server.CreateObject("ADODB.Recordset")
  14. objRS1.Open FLIGHTROUTE1, objConn1
  15.  
  16. 'retreive 1st row/date band routes
  17. If (IsNull(objRS1("Price_Band_1"))) Then
  18.     Response.Write ""
  19. Else
  20. Response.Write "<div id=""outboundroute"">" & objRS1("Anchor_Tag") 
  21. Response.Write "<fieldset class=""fieldsetspecialpricebox"">" & vbCrLf
  22. Response.Write "<legend>" & vbCrLf & "<span class=""specialtitlesmall"">" & objRS1("Flight_Route") & "</span>" & vbCrLf & "</legend>" & vbCrLf
  23. Response.Write "<table align=center cellpadding=0 cellspacing=0 class=""specialpricetable"">" & vbCrLf
  24. Response.Write "<tr><td class=""dateheadertd"">Flight Date/s</td></tr>" & vbCrLf
  25. Response.Write "<tr><td height=10>&nbsp;</td></tr>" & vbCrLf
  26.  
  27. 'write your table content
  28. Response.Write "<tr><td class=""datetd""><span class=""monthspan"">" & objRS1("Month_Band_1") & "&nbsp;</span>" & objRS1("Date_Band_1") & "</td></tr>"
  29. End If
  30.  
  31. 'retreive 2nd row/date band routes
  32. If (IsNull(objRS1("Price_Band_2"))) Then
  33.     Response.Write ""
  34.  
  35. Else
  36. Response.Write "<tr><td class=""datetd""><span class=""monthspan"">" & objRS1("Month_Band_2") & "&nbsp;</span>" & objRS1("Date_Band_2") & "</td></tr>"
  37. End If
  38.  
  39. 'retreive 3rd row/date band routes
  40. If (IsNull(objRS1("Price_Band_3"))) Then
  41.     Response.Write ""
  42.  
  43. Else
  44. Response.Write "<tr><td class=""datetd""><span class=""monthspan"">" & objRS1("Month_Band_3") & "&nbsp;</span>" & objRS1("Date_Band_3") & "</td></tr>"
  45. End If
  46.  
  47. 'retreive 4th row/date band routes
  48. If (IsNull(objRS1("Price_Band_4"))) Then
  49.     Response.Write ""
  50.  
  51. Else
  52. Response.Write "<tr><td class=""datetd""><span class=""monthspan"">" & objRS1("Month_Band_4") & "&nbsp;</span>" & objRS1("Date_Band_4") & "</td></tr>"
  53. End If
  54.  
  55. 'retreive 5th row/date band routes
  56. If (IsNull(objRS1("Price_Band_5"))) Then
  57.     Response.Write ""
  58.  
  59. Else
  60. Response.Write "<tr><td class=""datetd""><span class=""monthspan"">" & objRS1("Month_Band_5") & "&nbsp;</span>" & objRS1("Date_Band_5") & "</td></tr>"
  61. End If
  62.  
  63. Response.Write "</tr></table></fieldset>"
  64. Response.Write "</div>"
  65.  
  66. objRS1.Close
  67. Set objRS1 = Nothing
  68. objConn1.Close
  69. Set objConn1 = Nothing
  70. %>
but to cover all angles i think i need the first if statement to check if price band 1 - 5 are empty then do nothing - otherwise build table header and proceed..

but i dont think this is the way to do a if is null check on multiple recordset values???
Expand|Select|Wrap|Line Numbers
  1. 'check to see if there are any prices
  2. If (IsNull(objRS1("Price_Band_1" & "Price_Band_2" & "Price_Band_3" & "Price_Band_4" & "Price_Band_5"))) Then  
  3. Response.Write "" 
  4.  
  5. Else
  6. 'build table header
  7. Response.Write "<div id=""outboundroute"">" & objRS1("Anchor_Tag") 
  8. Response.Write "<fieldset class=""fieldsetspecialpricebox"">" & vbCrLf
  9. Response.Write "<legend>" & vbCrLf & "<span class=""specialtitlesmall"">" & objRS1("Flight_Route") & "</span>" & vbCrLf & "</legend>" & vbCrLf
  10. Response.Write "<table align=center cellpadding=0 cellspacing=0 class=""specialpricetable"">" & vbCrLf
  11. Response.Write "<tr><td class=""dateheadertd"">Flight Date/s</td></tr>" & vbCrLf
  12. Response.Write "<tr><td height=10>&nbsp;</td></tr>" & vbCrLf
  13.  
  14. 'retreive 1st row/date band routes
  15. If (IsNull(objRS1("Price_Band_1"))) Then
  16.     Response.Write ""
  17. Else
  18.  
  19. and so on...... etc%>
please advise

thanks in advance
Omar.
Nov 12 '10 #1
Share this Question
Share on Google+
3 Replies


danp129
Expert 100+
P: 321
If I'm understanding correctly, I would just change the SQL statement to only pull records that do not have a null or empty value. Then after opening the recordset you can see if the recordset is empty.
Expand|Select|Wrap|Line Numbers
  1. If objRS1.EOF Then
  2. 'do nothing
  3. Else
  4. 'your code here
  5. End If
Nov 15 '10 #2

100+
P: 120
I've been working on this problem since friday and managed to come up with a solution. took me ages to work it out though

this is how I adapted my if statement to check for null/not null on multiple values which works great;
Expand|Select|Wrap|Line Numbers
  1. If (NOT IsNull(objRSLGWYUL("Price_Band_1"))) OR (NOT IsNull(objRSLGWYUL("Price_Band_2"))) OR (NOT IsNull(objRSLGWYUL("Price_Band_3"))) OR (NOT IsNull(objRSLGWYUL("Price_Band_4"))) OR (NOT IsNull(objRSLGWYUL("Price_Band_5"))) Then 
  2.  
I now have another problem. but I will try fixing it if not I will open a new thread.

thanks
Omar.
Nov 17 '10 #3

P: 11
Expand|Select|Wrap|Line Numbers
  1. If not IsNull("COL1") or trim(COL1) = "" OR not IsNull("COL2") or trim(COL2) = "" ..... then
  2.  
  3. Else
  4.  
  5. End If
Apr 5 '13 #4

Post your reply

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