what is the Error in my nested if statement in for loop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    what is the Error in my nested if statement in for loop?

    hi
    currently i am doing car rental website and one of my update booking function encounter some problem which i also do not know where is wrong. basically i would to check through my Booking1 table if the id user posted over equal to any id in my Booking1 table. if exist, then we will let it proceed otherwise it will go to Notexist page
    to state to customer that this booking id do not exist. my code is in the following yet i don not why every time, it just go into else condition, even though my "if i.id == q:" condition is fulfilled. is this indention error or....syntax error. can anyone kindly help me with this. thanks in advance. :)

    [code=python]
    def confirmUp(reque st):
    Array=[]
    ba={}
    q=request.sessi on['BK_id']
    uID=request.use r.id
    #ba=Booking1.ob jects.get(id=q)
    #print ba.id

    for i in Booking1.object s.all():

    if i.id == q:
    print "PPPPPPPPP"
    ba=Booking1.obj ects.get(id=q)
    print "LLLLLLLLLLLLLL LL"
    Array.append(ba )
    return render_to_respo nse('proceed.ht ml',{'Array': Array })

    else:
    return HttpResponseRed irect("/Notexist/")
    [/code]
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by kang jia
    hi
    currently i am doing car rental website and one of my update booking function encounter some problem which i also do not know where is wrong. basically i would to check through my Booking1 table if the id user posted over equal to any id in my Booking1 table. if exist, then we will let it proceed otherwise it will go to Notexist page
    to state to customer that this booking id do not exist. my code is in the following yet i don not why every time, it just go into else condition, even though my "if i.id == q:" condition is fulfilled. is this indention error or....syntax error. can anyone kindly help me with this. thanks in advance. :)

    [code=python]
    def confirmUp(reque st):
    Array=[]
    ba={}
    q=request.sessi on['BK_id']
    uID=request.use r.id
    #ba=Booking1.ob jects.get(id=q)
    #print ba.id

    for i in Booking1.object s.all():

    if i.id == q:
    print "PPPPPPPPP"
    ba=Booking1.obj ects.get(id=q)
    print "LLLLLLLLLLLLLL LL"
    Array.append(ba )
    return render_to_respo nse('proceed.ht ml',{'Array': Array })

    else:
    return HttpResponseRed irect("/Notexist/")
    [/code]
    Have you tried enclosing the q in " " and see if that works?

    Regards,

    Jeff

    Comment

    • kang jia
      New Member
      • Jun 2007
      • 88

      #3
      Originally posted by numberwhun
      Have you tried enclosing the q in " " and see if that works?

      Regards,

      Jeff
      i do have tried before, but it is the same result, can help me with this.. is indentation or...i am really not sure where went wrong. thanks for any help:)

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by kang jia
        i do have tried before, but it is the same result, can help me with this.. is indentation or...i am really not sure where went wrong. thanks for any help:)
        You should check to see if i.id and q are the same type (3 != "3").

        Comment

        Working...