I want to create a dashboard widget in my web app. The first step is to count the frequency of pos, neg and neu in mysql from two table. I tried to find the solution in Flask, but not many. Hope u can help me.
The error that I got is:
MySQLdb._exceptions.OperationalError: (1241, 'Operand should contain 1 column(s)')
Table in mysql:
ques9
ques10
My code:
@app.route('/we/<string:programid>')
def we(programid):
# Create cursor
cur = mysql.connection.cursor()
result = """SELECT(
(SELECT programid,sentiment, COUNT(*)
FROM ques9 AS question9
WHERE programid= %s
GROUP BY sentiment),
(SELECT programid,q10_sentiment, COUNT(*)
FROM ques10 AS question10
WHERE programid=%s
GROUP BY q10_sentiment ))"""
data_tuple = (programid, programid)
cur.execute(result, data_tuple)
program = cur.fetchall()
mysql.connection.commit()
if result > 0:
return render_template('we.html',program=program)
else:
msg = 'No Results Found'
return render_template('we.html', msg=msg)
# Close connection
cur.close()