#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13

    Question A certainl part of an if() structure never gets executed.


    Code:
    		if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ):
    			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
    		elif not re.search( '=', month ) and not re.search( '=', year ):
    			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
    		elif not re.search( '=', year ):
    			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )
    		else:
    			print('''<h2>Πώς να γίνει αναζήτηση αφού δεν επέλεξες ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?''')
    			print( '''<meta http-equiv="REFRESH" content="5;/cgi-bin/pelatologio.py">''' )
    			sys.exit(0)
    
    		data = cur.fetchall()
    		
    		hits = money = 0
    		
    		for row in data:
    			hits += 1
    			money = money + row[2]
    
    ......
    ......
    selects based on either name, month, year or all of them

    The above if structure works correctly *only* if the user sumbits by form:

    name, month, year
    or
    month, year

    If, he just enter a year in the form and sumbit then, i get no error, but no results displayed back.

    Any ideas as to why this might happen?
    Last edited by Nik; June 11th, 2013 at 03:21 PM.
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo