感谢您对您的帮助我正在做一个学校项目。我正在尝试保存一些数据,所以让我解释一下:Picture因此在图片中,对于每个练习,我都有一个标记。有一张表格供练习者获取练习名称,我要保存每个练习的标记,在一个名为mark_exercice的表中,其中包含练习的ID和标记。她是我到目前为止所做的代码:
<table class="tg">
<tr>
<th class="tg-eiws">Exercice</th>
<th class="tg-fymr">M</th>
<th class="tg-fymr">E</th>
<th class="tg-fymr">C</th>
<th class="tg-fymr">B</th>
<th class="tg-fymr">A</th>
</tr>
<?php foreach ($missionsPns['exercicespn'] as $key => $missionsPn): ?>
<tr>
<td class="tg-0lax"><?php echo h($missionsPn['NOM']); ?></td>
<td class="tg-0lax"><div ><input name="data[noteexercice][note]" value="M" type="checkbox" id="NoteM"></div></td>
<td class="tg-0lax"><input name="data[noteexercice][note]" value="E" type="checkbox" id="NoteE"></td>
<td class="tg-0lax"><input name="data[noteexercice][note]" value="C" type="checkbox" id="NoteC"></td>
<td class="tg-0lax"><input name="data[noteexercice][note]" value="B" type="checkbox" id="NoteB"></td>
<td class="tg-0lax"><input name="data[noteexercice][note]" value="A" type="checkbox" id="NoteA"></td>
</tr>
<?php endforeach; ?>
</table>
当我对请求数据进行调试时,我得到了这个:array(
'noteexercice' => array(
'note' => 'A'
)
)
所以我希望我可以将标记与练习名称一起保存。
尝试一下:
<table class="tg">
<tr>
<th class="tg-eiws">Exercice</th>
<th class="tg-fymr">M</th>
<th class="tg-fymr">E</th>
<th class="tg-fymr">C</th>
<th class="tg-fymr">B</th>
<th class="tg-fymr">A</th>
</tr>
<?php foreach ($missionsPns['exercicespn'] as $key => $missionsPn): ?>
<tr>
<td class="tg-0lax"><?php echo h($missionsPn['NOM']); ?></td>
<td class="tg-0lax"><div ><input name="data[noteexercice][$missionsPn['ID']][]" value="M" type="checkbox" id="NoteM"></div></td>
<td class="tg-0lax"><input name="data[noteexercice][$missionsPn['ID']][]" value="E" type="checkbox" id="NoteE"></td>
<td class="tg-0lax"><input name="data[noteexercice][$missionsPn['ID']][]" value="C" type="checkbox" id="NoteC"></td>
<td class="tg-0lax"><input name="data[noteexercice][$missionsPn['ID']][]" value="B" type="checkbox" id="NoteB"></td>
<td class="tg-0lax"><input name="data[noteexercice][$missionsPn['ID']][]" value="A" type="checkbox" id="NoteA"></td>
</tr>
<?php endforeach; ?>
</table>
所以会有这样的输出:
array(
'1' => array('C', 'B', 'A'),
'2' => array('B'),
'3' => array('M', 'A')
);
而且您可以像这样保存它:
$this->loadModel('MarkExercise');
foreach($data as $dataKey => $dataValue) {
foreach ($dataValue as $datum) {
$toSave = array('exercise_id' => $dataKey, 'mark' => $datum);
this->MarkExercise->save($toSave);
}
}
我希望它会有所帮助。