#!"c:\python310\python.exe" from dbconfig import * import pymysql import warnings warnings.filterwarnings('ignore') # cgi: Support module for Common Gateway Interface (CGI) scripts. # cgitb: Traceback manager for CGI scripts # cgitb.enable(): enable trace back feature import cgi import cgitb cgitb.enable() # Establish a cursor for MySQL connection. db = get_mysql_param() cnx = pymysql.connect(user=db['user'], password=db['password'], host=db['host'], # port needed only if it is not the default number, 3306. # port = int(db['port']), database=db['database']) cursor = cnx.cursor() # Create HTTP response header print("Content-Type: text/html;charset=utf-8") print() # Create a primitive HTML starter print ('''
''') form = cgi.FieldStorage() major = form.getfirst('major') if major is None: print ('Please enter a valid major code in the URL.') print ('') quit() query = ''' SELECT DISTINCT s.stuId, CONCAT(s.fname, ' ', s.lname) AS student, s.ach, IFNULL(CONCAT(f.fname, ' ', f.lname), 'N/A') AS advisor FROM student AS s LEFT JOIN faculty AS f ON (s.advisor = f.facId) WHERE s.major = %s ''' cursor.execute(query, major) # Read data and generate code for a HTML table. print('''Student Id | Name | Accumulated credits | advisor |
---|---|---|---|
{} | {} | {} | {} |
100000 | Tony Hawk | 40 | Paul Smith |