Python Forum
Problem in DB requests using if()s
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in DB requests using if()s
#1
Hello, iam reposting my previous post more clear written this time:

@app.route( '/seek', methods=['GET', 'POST'] ) def seek():	pdata = ''	name = request.args.get('name')	month = request.args.get('month')	year = request.args.get('year')	try:	if name and month.isdigit() and year.isdigit():	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) )	if (not name) and month.isdigit() and year.isdigit():	cur.execute( '''SELECT * FROM jobs WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (month, year) )	if name and (not month) and year.isdigit():	cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, year) )	if (not name) and (not month) and year.isdigit():	cur.execute( '''SELECT * FROM jobs WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )
Although the first two if()s work properly the third and forth doesnt and i cannot seem to understand why.
This is the data that form user selection upon drop down menus:

name = month = year = ''	# populate names, months, years	names.append( '' )	names.sort()	months = ( '', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μάϊος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος' )	years = ( '', 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 )	pdata = pdata + '''	<br><h3><br><font color=red size=6> Επιλεκτική Αναζήτηση </font><br>	<form methods="POST" enctype="multipart/form-data" action="%s">	<select name="name"><option> %s </option></select>	<select name="month"> %s </select>	<select name="year"><option> %s </option></select>	<br>	<input type="image" src="/static/img/play.gif" name="seek" value="<Αναζήτηση>">	</form>	''' % (url_for( 'seek' ),	'</option><option>'.join( names ),	''.join( map( lambda args: '<option value="%s">%s</option>' % (args[0], args[1]), enumerate( months ) ) ),	'</option><option>'.join( list( map( str, years ) ) ) )[python]
Can you help me please? This is troubling me days now....
Reply


Messages In This Thread
Problem in DB requests using if()s - by nikos - Feb-09-2019, 06:06 PM
RE: Problem in DB requests using if()s - by woooee - Feb-09-2019, 06:35 PM
RE: Problem in DB requests using if()s - by nikos - Feb-09-2019, 07:33 PM
RE: Problem in DB requests using if()s - by nikos - Feb-09-2019, 11:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'import requests' problem Curbie 2 1,401 Aug-14-2024, 01:04 AM
Last Post: Curbie
  Import requests/beautifulsoup problem Jokadaro_ 3 4,001 Dec-05-2021, 01:22 PM
Last Post: Jokadaro_
  Requests problem ZarKx 3 4,859 May-22-2018, 12:22 PM
Last Post: ZarKx

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.