【问题标题】:Why is the select statement not selecting all the rows from the database table? It is ignoring the first entry every time为什么 select 语句没有从数据库表中选择所有行?它每次都忽略第一个条目
【发布时间】:2020-03-06 16:18:58
【问题描述】:

我正在尝试将数据库表中的名称放入下拉列表中,但 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>
""")

样本数据

输出

【问题讨论】:

  • 请通过包含失败的示例数据将其设为minimal reproducible example
  • 旁注:没有order by 子句,first 记录的概念实际上没有意义......
  • 但是在哪里打开

标签: python html sql forms


【解决方案1】:

好的,这里是一个例子

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-05
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 2016-08-22
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多