为啥 select 语句没有从数据库表中选择所有行?它每次都忽略第一个条目
Posted
技术标签:
【中文标题】为啥 select 语句没有从数据库表中选择所有行?它每次都忽略第一个条目【英文标题】: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 记录的概念实际上没有意义......
但是在哪里打开
【参考方案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)
【讨论】:
以上是关于为啥 select 语句没有从数据库表中选择所有行?它每次都忽略第一个条目的主要内容,如果未能解决你的问题,请参考以下文章