我有 while 循环从 mysql 表中获取信息。但不知道如何找到包含相同内容的 las 条目factor_id
并在其后添加附加新元素。
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 的最后一个条目之后添加其他元素