在對我的看法,我有以下形式:從陣列獲取的數據是無效的
<table align="center" border="1">
<tr>
<td>Identificação</td>
<td>Conc, %</td>
<td>Classificação 67/548/CEE</td>
<td>Classificação 1272/2008 (CLP)</td>
</tr>
<tr>
<td>
<textarea rows="4" cols="30" name="componentes[0][identificacao]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][conc]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][classificacao_cee]"></textarea>
</td>
<td>
<textarea rows="4" cols="30" name="componentes[0][classificacao_clp]"></textarea>
</td>
</tr>
</table>
<div id="outro_curso"></div>
<p class="submit">
<button id="novo_curso">Add Curso</button>
</p>
正如你所看到的,我使用的是多維數組。我這樣做,因爲當我點擊「添加Curso」按鈕時,我調用一個jquery函數來生成另一個表,就像上一個表一樣。文本區域的名稱將是componentes[1][identificacao]
,componentes[1][conc]
等...
注意:我可以使用該按鈕來生成我想要的表的次數。
現在,我的問題是如何讓我的CodeIgniter模型中處理這些數據。我試圖將數據保存到$componentes
陣列(稍後插入到數據庫中),但我想有什麼錯我的代碼:
$componentes;
foreach ($this->input->post('componentes') as $key => $value){
$componentes[$key]['identificacao']=$value[$key]['identificacao'];
$componentes[$key]['conc']=$value[$key]['conc'];
$componentes[$key]['classificacao_cee']=$value[$key]['classificacao_cee'];
$componentes[$key]['classificacao_clp']=$value[$key]['classificacao_clp'];
}
有人可以給我一點幫助嗎?
編輯:
我忘了提,我得到的錯誤:
Invalid argument supplied for foreach().
所以我不知道如果我的foreach ($this->input->post('componentes') as $key => $value){
是正確的,或者是在線路的一些問題內。
從快看那個元素就快到了,我猜你需要這個:'$ componentes [$ key] ['identificacao'] = $ value ['identificacao'];' – Mudshark
我編輯了我的帖子Mudshark。現在我無法測試您的建議,因爲我的foreach出現錯誤。 – user1511579