mysqlテーブルから情報を取得するためのwhileループがあります。factor_id
しかし、同じものを含むlasエントリを見つけて、その後に新しい要素を追加する方法を理解することはできません。
if ($this->_db->numRows() > 0) {
$i = 1;
$j = '';
$row = '';
while ($row = mysqli_fetch_assoc($res_info)) {
if ($row['task_factor_category'] != $j) {
$title = '<tr><td colspan="4" class="title" style="text-align: left;">' . $row['task_factor_category'] . '</td></tr>';
$comment = '<tr><td class="title" style="text-align: left" colspan="4">' . $this->_glan['comments'] . '</td></tr><tr><td colspan="4"><textarea cols="82" rows="3" name="factor_comment[' . $row['factor_id'] . ']" id="' . $row['factor_id'] . '"></textarea></td></tr>';
} else {
$title = false;
$comment = false;
}
$this->reg['edit_fields']['factors'] .= $title . '<tr>
<td>
' . $row['factors'] . '
</td>
<td>
<input type="radio" name="task_factor[' . $i . '_' . $row['factor_id'] . ']" value="1" />
</td>
<td>
<input type="radio" name="task_factor[' . $i . '_' . $row['factor_id'] . ']" value="2" checked />
</td>
<td>
<input type="radio" name="task_factor[' . $i . '_' . $row['factor_id'] . ']" value="3" />
</td>
</tr>
';
$j = $row['task_factor_category'];
$i++;
}
}
出力は次のようになります。
//results with $row['factor_id'] = 10;
title
1. entry
2. entry
3. entry
4. entry
5. entry
//need new element here
//results with $row['factor_id'] = 11;
title
1. entry
2. entry
3. entry
4. entry
5. entry
//need new element here
......
同じ因子IDを含む最後のエントリの後に要素を追加する必要があります