简体   繁体   English

我无法连续看到从我的 MySQL 数据库到我的 html 页面的最后插入数据

[英]I can't see continuously the last insert data from my MySQL database to my html page

I use flask framework and with this code i get the last insert data,but i want to display continuously the last insert.我使用 flask 框架并使用此代码获得最后插入数据,但我想连续显示最后插入。 When i reboot the flask framework i get it.Any help?当我重新启动 flask 框架时,我明白了。有帮助吗?

app.py应用程序.py

@app.route("/sensor" , methods=['POST','GET'])
def sensor():
   
   cursor = db.cursor()

   cursor.execute("SELECT Id,temperature,humidity FROM Bseonsor WHERE Id=(SELECT MAX(Id) FROM Bseonsor)")

   results = cursor.fetchall()
   
   return render_template('sensor.html',results=results)

sensor.html传感器.html

<div>
    <table border="1" cellpadding="5" cellspacing="5">
    {% for row in results %}
        <tr> {{ row[1] }} {{ row[2] }} </tr>
    {% endfor %}
    </table>
</div>

I believe when making selections to the database, you should use the buffered=True argument.我相信在对数据库进行选择时,您应该使用buffered=True参数。

Note about selections: Also in the above program, the specified the size is 2 to fetch two records.关于选择的注意事项:同样在上述程序中,指定大小为 2 以获取两条记录。 Also, we set buffered=True in connection.此外,我们在连接中设置了 buffered=True。 Cursor () method to avoid MySQL Unread result error. Cursor() 方法避免 MySQL 未读结果错误。

About mysql-connector selections 关于 mysql-connector 选择

It should look something like this: cursor = db.cursor(buffered=True) This can be a bit of a pain when trying to use prepared SQL though.它应该看起来像这样: cursor = db.cursor(buffered=True)不过,当尝试使用准备好的 SQL 时,这可能会有点痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Django 管理站点中查看我的 MySQL 数据库? - How can I see my MySQL database in Django admin site? 我如何从我的 sqlite 数据库中查询和获取数据,即使我的搜索输入有相似的单词彼此分开(不是连续的) - How can I query and get data from my sqlite database even when my search input have similar words that is apart from each other (not continuously) 无法从我的Tkinter GUI的数据库中检索数据 - Can't retrieve data from my database for my tkinter GUI 如何将我从远程MySQL数据库选择的一些行插入本地MySQL数据库 - how do I insert some rows that I select from remote MySQL database to my local MySQL database 如何从持续运行脚本的另一台 PC 访问数据? - How can I access data from my other PC that is continuously running a script? django我看不到我的表格 - django i can't see my form 为什么看不到我的LabelFrames? - Why can't I see my LabelFrames? 如何将变量的值插入 MySQL 数据库? - How do I insert the value of my variable into my MySQL database? 当我将它们映射在一起时,为什么不能以Pyside形式看到模型中的数据? - Why can't I see the data from my model in this Pyside form while I did map them together? 如何将数据插入到 MySQL 数据库中? - How can I insert data into a MySQL database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM