I have 3 fieldsa within a form , a name field, a month field and a year field.
As first value fields have '=======' whuch meant to mean not selected.
No the user can make combination asking how many money
name + month + year
month + year
name + year
year
that is why i tried with the following code
As first value fields have '=======' whuch meant to mean not selected.
No the user can make combination asking how many money
name + month + year
month + year
name + year
year
that is why i tried with the following code
if '=' not in name + month + year: cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, month, year) ) elif '=' not in month + year: cur.execute( '''SELECT * FROM jobs WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (month, year) ) elif '=' not in name + year: cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, year) ) elif '=' not in year: cur.execute( '''SELECT * FROM jobs WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )The if and the first elif are returnings results properly, while the other 2 elifs always return mixed results mostly of them irrelevant.