473,406 Members | 2,705 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,406 software developers and data experts.

help with asp classic if else loop

120 100+
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. £
  4. £219     Dec 7
  5. £149     Jan 13, 14, 16, 20, 21, 23
  6. £179     Feb 3, 4, 6, 10, 11, 13, 17, 18, 24, 25, 27
  7. £                                                  
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
3 4075
danp129
323 Expert 256MB
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
omar999
120 100+
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
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

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

Similar topics

4
by: ptrlks | last post by:
Hi again, the problem is in this code:ElseIf Right(rsBokad("aktivitet"), 3) = "Cup" Then dStartDate = Cdate(rsBokad("startDatum")) dEndDate = Cdate(rsBokad("endDatum"))
3
by: John F. | last post by:
Hi all, I'm searching fulltime for days now, and I don't find the solution, so I'm thinking this is more a bug :( If i use following code in form&subforms:
4
by: jstaggs39 | last post by:
I have a form that requires a start date and an end date as input for the parameters then runs the form which open queries which are designed to populate certain tables. As it stands now, i can...
0
by: /2ez|n | last post by:
I found the answer, but thanks for all the help! For my c++ class I have to make a small win32 console program that calculates body mass index. The user will enter in a their first and...
6
by: JDK721 | last post by:
I need help with writing a loop that prints 1-20 to the screen but skips 15, 16, and 17. I know how to write a for loop that prints any number range, such as 5-200 1-20 etc. But I don't know how...
2
by: chiefs | last post by:
I'm a beginner in C++!! #1-Dont know how to loop end when int q(entered); int q is a very large # when ran: printf("\n%i#of Questions\n", q); #2-is the line "how many questions Right"?...
3
by: stressedstudent | last post by:
I dont know where I am going wrong so I dont know which part to post, this is what I have, can anyone help me figure out where I am going wrong? THanks for any and all help. // into to c++ //...
12
by: zalery | last post by:
so i'm trying to set up this exponents loop, keep in mind this is my first year in computer science so my knowledge of script is somewhat minimal. basically this assignment (or at least part of it)...
1
by: kenneth6 | last post by:
#include <iostream> using namespace std; int main() { char firstname; char finalFirstname; cout << "Enter your first name: "; int num = 0;
3
Thekid
by: Thekid | last post by:
I need help writing a loop for this. image = ImageGrab.grab((0,0,800,800)) box = (100,100,400,400) im = image.crop(box) im1 = im.save("screen.jpg") # at this point I need to rotate the image...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.