#!"c:\python310\python.exe" from dbconfig import * import pymysql import warnings warnings.filterwarnings('ignore') import cgi import cgitb cgitb.enable() print("Content-Type: text/html;charset=utf-8") print() print (''' ''') #  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() 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 CONCAT(s.fName, ' ', s.lName) AS student, COUNT(e.classId) as num_classes FROM student AS s LEFT JOIN enroll AS e ON (s.stuId = e.stuId) WHERE s.major = %s GROUP BY s.stuId, student ORDER BY s.lName, s.fName; ''' cursor.execute(query,(major,)) row = cursor.fetchone() if row is None: print ('Sorry, no major with code {}. Please enter a valid major code in the URL.'.format(major)) print ('') quit() print('''

Studnts and their numbers of classes enrolled in the major {}:

'''.format(major)) while row is not None: (student, count) = row print("".format(student, count)) row = cursor.fetchone() cursor.close() cnx.close() print ('''''')
Student NameNumber of classes
{}{}