Please, Need Help With "if..elseif..else..end If"

Discussion in 'C#' started by jusa, Jul 28, 2008.

  1. #1
    can anybody help me with the question below:

    my table consists of the fields like
    IdTour
    TourName
    TourType (transfer, tour)
    Tourtime

    i want to come out with formula that could return rates next to the tour name based on the time and tourtype in the following rate list

    transfer 18:00 - 6:00 $20
    transfer 6:00 - 18:00 $10
    tour 23:59 - 10:00 $30
    tour 10:01 - 23:59 $10

    I have tried this with "if...elseif..else..end if" but it doesn't work

    the half working script i'm using is as follows:

    
    <%
    set c=server.createobject("adodb.connection")
    c.open("jusa")
    
    q="select * from db"
    
    dim r
    response.write(q)
    set r=c.execute(q)
    
    do while r.eof
    
    <tr>
    <td>
    <%=r(TourName)%>
    </td>
    <td>
    if r("tourtype")="transfer" and r("Tourtime")<#23:59# and r("Tourtime")>#10:00# then 
    response.write("10")
    elseif r("tourtype")="transfer" and r("Tourtime")<#10:00# and r("Tourtime")>#23:59# then
    response.write("20")
    ElseIf r("tourtype")="tour" and r("Tourtime")<#18:00# and r("Tourtime")>#6:00# then
    response.write("15")
    ElseIf r("tourtype")="tour" and r("Tourtime")>#18:00# and r("Tourtime")<#6:00# then
    response.write("30")
    end if
    
    </td>
    </tr>
    
    <%
    r.movenext
    loop
    c.close
    %>
    
    Code (markup):
     
    jusa, Jul 28, 2008 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    what doesnt work? do you get any error?
     
    ludwig, Jul 28, 2008 IP
  3. jusa

    jusa Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no error, the problem is it doesn't return rate for some tours, but for some does.. :(
     
    jusa, Jul 29, 2008 IP
  4. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    180
    #4
    The best solution for this would be to create the tables like this

    TourTypeTable
    ----TourTypeID
    ----TourTypeName

    TourTimeSlotTable
    ---TimeSlotID
    ---TourType
    ---TimeSlotDescription

    TourTable
    ---TourID
    --- TourName
    --- TourTypeID ;Foreign key
    ---TourTimeSlotID 'Foreign key

    Just do a join of all the 3 tables and you will get the correct values. No cryptic SQL necessary. You will need to do an outer join selecting all records from ToursTable
     
    vihutuo, Aug 4, 2008 IP