asp頁面中的checkbox迴圈讀取並插入資料庫裡的思路

來源:互聯網
上載者:User
選取多個checkbox刪除的語句是:
delete from Table where ID in request.form("ID")

如果是一個form表單,裡面有一些輸入框,另外有一個checkbox有很多選擇框,選中checkbox的checked之後,我要把選中的值和其他一些表單裡的資訊寫到資料庫裡,怎麼操作呢?

思路如下:假設a.asp 有一個
<input type="checkbox" name="id" value="變數ID">
這裡ID值不同,大概有幾十個選項吧。
form到b.asp裡,
那麼b.asp裡首先要做的是a.asp裡選中了多少個id為checkbox為checked狀態。
文法如下:
Count=request.form("id").count
假設計算出來Count為35,則說明有35個name為id的checkbox選中的,也就是說插入資料庫裡需要寫入35條資料,迴圈如下:
for i=1 to Count
ID=request.form("id")(i)
這裡是sql的普通插入語句,上面的ID為當選中的記錄為i時,讀取第i的條件時,id變數值
next

還有一種方法大致相同只不過得到迴圈次數的方法不同,簡單介紹一下

我有很多個checkbox在表單裡面,name的名字都一樣,希望能多選,然後寫進資料庫。
然後我想了一下,決定迴圈讀取
    dim sql,project_id,expert_name,expert_nameStr
    project_id=request.form("project_id")
    expert_nameStr=request.form("expert_name")
    expert_nameStr=split(expert_nameStr,",") ''split函數將得到的字元創以逗號為分割對象將expert_nameStr分開
    for i=0 to ubound(expert_nameStr)         '''ubound函數得到分開後的字串的最大數
    expert_name=expert_nameStr(i)

    Set Rs = server.createobject("ADODB.Recordset")
    sql="select * from pingfen where pingfen_project_id="&project_id
    rs.open sql,conn,1,3
    if rs.eof then
    sql="insert into pingfen (pingfen_project_id,pingfen_expert_name) values ('"&project_id&"','"&expert_name&"')"
    conn.execute(sql)
    else
       rs("pingfen_expert_name")=expert_name
    sql="update pingfen set pingfen_expert_name='"&expert_name&"'where pingfen_project_id="&project_id
    conn.execute(sql)   
    end if
    Next
    Call AlertAndJump("操作成功!","../admin/fenpeizhuanjia.asp","smile")

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.