我的数据库中有2列,分别为description
和url
我想选择这两个选项,但只向用户显示description
。问题是,当我遍历fetchall命令时,它要么选择这两个字符,要么仅选择单个字符。这是我的代码:
connection = pymysql.connect(user='fake', passwd='fake', host='db', port=1111, db='fake_db_name')
searchResult = []
try:
with connection.cursor() as cursor:
pushpin_sql = "SELECT description, url FROM pushpin WHERE pushpin.description LIKE '%" + str(searchTerm) + "%'"
result = cursor.fetchall()
for col in result:
searchResult+=col
connection.commit()
finally:
connection.close
输出是这样的:
这是一只可爱的狗
http://jiangzhenling.com/img/CS6400/dog/dog1.png
如果我将其更改为:
for col1,col2 in result:
searchResult+=col1
然后它仅连接单个字符
输出为:
t
h
i
..等等。如何使它仅连接我的描述而不是我的网址?
答案 0 :(得分:1)