我正在用python做一个项目。我有一个HTML,我有两个选择一个选择状态,一个选择名称,我有一个过滤按钮,当我点击按钮相应的动作发生在python.I有一个数据库“bucketlist”,我有名称,密码,状态列基于选定状态和名称我应该显示表。我做了一个状态和一个表,如果我选择多个它不工作它只考虑第一个选择一个。请帮帮我。
这是我的代码:
sample.Html:
<form class="form-inline" action="/admin" method="post">
<div class="form-group">
<label class="tohrlable">State:</label>
<select name="text1[]" class="selectpicker" data-size="5" multiple data-live-search="true" data-selected-text-format="count > 2">
<option value="All"selected>All</option>
<option value="tamilnadu">tamilnadu</option>
<option value="Andhara">Andhara</option>
<option value="Keraal">Kerala</option>
</select>
</div>
<div class="form-group">
<label class="tohrlable">Name:</label>
<select name="text2[]" class="selectpicker" data-size="5" multiple data-live-search="true" data-selected-text-format="count > 2">
<option selected>All</option>
<option value="preethi">preethi</option>
<option value="saranya">saranya</option>
<option value="Tharini">Tharini</option>
</select>
</div>
<!-- Accent-colored raised button with ripple -->
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="background:#2196f3">
Filter
</button>
</form>
吡啶:
@app.route('/')
def hello_world():
return render_template("sample.html")
@app.route('/admin',methods=['POST','GET'])
def hello():
if request.method == 'POST':
conn = mysql.connect()
cursor = conn.cursor()
a = request.form.getlist('text1[]')
b = ' '.join(a)
c = request.form.getlist('text2[]')
d = ' '.join(c)
print d
Name = d
cursor.execute("select Name from user_master WHERE Name='" + Name + "'")
data = cursor.fetchall()
return jsonify({"data": data})
答案 0 :(得分:0)
您可以尝试IN
查询:
Name = "'" + "','".join(d) + "'"
cursor.execute("select Name from user_master WHERE Name IN (" + Name + ")"