def get_constituency_result_2009(db,constituency_id):
cursor = db.cursor()
cursor.execute('''SELECT ca.id, ca.fullname, p.id, p.name, l.votes
FROM last_time_results l, candidate ca, constituency co, party p
where l.constituency_id=co.id and l.candidate_id=ca.id
and l.party_id=p.id and l.candidate_id=ca.id and l.constituency_id=co.id
and l.constituency_id='''+ constituency_id +''' order
by l.votes desc;''')
results=[]
total_votes=0
for row in cursor.fetchall():
temp_map={}
temp_map['candidate_id']=row[0]
temp_map['candidate_name']=cgi.escape(row[1]).title()
temp_map['party_id']=row[2]
temp_map['party_name']=cgi.escape(row[3]).title()
temp_map['votes']=row[4]
total_votes=total_votes+row[4]
results.append(temp_map)
new_results = []
for rec in results:
rec['total_votes']=total_votes
new_results.append(rec)
return json.dumps(new_results)
评论列表
文章目录