python - 为什么 select 语句没有从数据库表中选择所有行?每次都会忽略第一个条目

标签 python html sql forms

我试图将数据库表中的名称放入下拉列表中,但 SELECT 语句忽略第一行。

我正在使用 python 来完成它。

sql = "SELECT * FROM ArtistDetails"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
    print(f"<option>{x[1]}</option>")
print("""
</select>
<br>
""")

示例数据

Sample data

输出

Output

最佳答案

好的,这是一个例子

sql = "SELECT Artist_Id,ArtistName FROM ArtistDetails"
mycursor.execute(sql)
myresult = mycursor.fetchall()
tag = '<select>'
for row in myresult:
        print row["Artist_Id"], row["ArtistName"]
        tag=tag+f"<option value='{row["Artist_Id"]}'>{row["ArtistName"]}</option>"

tag=tag+'</select>'
print(tag)

关于python - 为什么 select 语句没有从数据库表中选择所有行?每次都会忽略第一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58793555/

相关文章:

python - Django 表单 : what is the best way to modify posted data before validating?

python - 没有名为 __future__ 的模块

python - 将 PostgreSQL 枚举与 TypeDecorator 相结合

python - matplotlib 中带垂直线的图例

html - safari 的 flexbox 行和列 ul li 菜单

javascript - 如何在 html 选项文本和值中插入 xml 文本和值

php - 用户操作后更新数据库

sql - 为什么 SUM(a + b) != SUM(a) + SUM(b) 在 Hive 中?

sql - 删除时如何在存储过程中使用2个表?

mysql - 使用内部连接计算特定字段