我正在將數據從查詢輸出到html表中進行表示。在表格的右下角我有一個「更新」按鈕和一個「刪除」按鈕。更新html表中的特定行 - ColdFusion
我所試圖做的是:
- 當我按下更新按鈕模式打開。在該模式中,我有一個表格,我想要預先定義當前行的值並能夠編輯特定行
- 當我按下一行上的刪除按鈕時,我希望該行被刪除並重新加載頁面
這是我的HTML表格,右邊的最後兩列是按鈕
**Survey Name** **Category** **Weight** **Update** **Delete**
Consultation Ambiance 20 Update Delete
Consultation Consultation 40 Update Delete
Consultation Follow Up 40 Update Delete
這是生成表我的第一個查詢
<cfquery name="categories" datasource="#dsn#">
select s.name, s.id as surveyid, rc.categoryname, rc.id as categoryid, sc.cweight
from survey_categories sc
join surveys s on s.id = sc.surveyidfk
join rating_categories rc on rc.id = sc.categoryidfk
where sc.surveyidfk='#form.survey#'
</cfquery>
這是我訪問的形式當我按下「更新」
- 這種形式圍繞選擇標籤額外CFLOOP得到,我在的情況下,用戶需要到數據庫類別的休息改變類別。
- 因此,舉例來說,如果我按在我的表中的第二行中的更新按鈕,這種形式應該在下拉菜單,在底部文本框
一張小紙條,可以幫助的人數
40
有Consultation
輸出表的第一個查詢也會輸出一個唯一的id(id,surveyName,Category,Weight)。那麼到底更新查詢會是這樣的update categories set category='Example', weight='30' where id='345'
我不知道多少,這可以提供幫助。
<cfoutput>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 id="myModalLabel">Update</h3>
</div>
<div class="modal-body">
<form name="update" action="updateSCpair.cfm" method="post">
<input type="text" value="#categories.name#" class="input-xlarge" disabled> <br />
<select name="categories">
<cfloop query="ratingCat">
<option value="#ratingCat.id#" >#ratingCat.categoryName#</option>
</cfloop>
</select>
<br />
<input class="span3" type="number" placeholder="Enter Category Weight" required >
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</form>
</div>
</cfoutput>
UPDATE 爲了使它更清楚,因爲我覺得我寫的太多了。我需要調用表單提交的模式。我將需要用表單替換當前的按鈕,然後通過隱藏的變量傳遞所有數據。問題是這不適合我。我在這裏找到了另一個例子,但它似乎沒有工作。 EXAMPLE
那什麼不起作用?提交更新表單時,您應該能夠使用呈現的表重新加載頁面,並且假設更新查詢成功,則查詢的值應反映更新。 Re:刪除操作,人們通常會將刪除按鈕/圖標/以任何形式提交給處理頁面,並將其刪除。您也可以使用AJAX請求單擊刪除按鈕來完成同樣的事情。 – existdissolve
好吧,當我按更新時,正在傳遞到彈出窗口的值並不反映我真正想要更新的值 – Geo
請使用cfqueryparam,否則您將自己開放給SQL注入 – duncan