def query(self, sql):
connect = self.connect()
cur = connect.cursor()
cur.execute(sql)
index = cur.description
result = []
for res in cur.fetchall():
row = {}
for i in range(len(index)-1):
row[index[i][0]] = res[i]
result.append(row)
connect.close()
return result
这个方法返回查询结果就是带字段名的{‘字段名’:‘值’}
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/6a63f6246b600c335954b47a164c510fd9f9a157?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
我现在能连到数据库查出表,但不知道怎么通过html显示,我问有的人说是用ajax,但是我不太懂。