将多个下拉列表添加到SQL数据库中,可以通过以下步骤实现:
from flask import Flask, request
import sqlite3
app = Flask(__name__)
@app.route('/add_dropdown_options', methods=['POST'])
def add_dropdown_options():
dropdown1_options = request.form.getlist('dropdown1')
dropdown2_options = request.form.getlist('dropdown2')
dropdown3_options = request.form.getlist('dropdown3')
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
for option in dropdown1_options:
cursor.execute("INSERT INTO dropdown_options (dropdown_name, option_value) VALUES (?, ?)", ('dropdown1', option))
for option in dropdown2_options:
cursor.execute("INSERT INTO dropdown_options (dropdown_name, option_value) VALUES (?, ?)", ('dropdown2', option))
for option in dropdown3_options:
cursor.execute("INSERT INTO dropdown_options (dropdown_name, option_value) VALUES (?, ?)", ('dropdown3', option))
conn.commit()
conn.close()
return 'Dropdown options added to the database successfully.'
if __name__ == '__main__':
app.run()
var dropdown1Options = ['Option 1', 'Option 2', 'Option 3'];
var dropdown2Options = ['Option A', 'Option B', 'Option C'];
var dropdown3Options = ['Option X', 'Option Y', 'Option Z'];
$.ajax({
url: '/add_dropdown_options',
type: 'POST',
data: {
dropdown1: dropdown1Options,
dropdown2: dropdown2Options,
dropdown3: dropdown3Options
},
success: function(response) {
console.log(response);
}
});
通过以上步骤,可以将多个下拉列表的选项值添加到SQL数据库中。请注意,上述示例代码仅供参考,实际实现可能因使用的编程语言、框架和数据库而有所不同。
领取专属 10元无门槛券
手把手带您无忧上云