#php #codeigniter #for-loop
#php #codeigniter #for-цикл
Вопрос:
Я пытаюсь показать 2 изображения подряд.Вкратце, когда отображается изображение, следующее изображение переходит в новую строку.я хочу, чтобы, когда 2 изображения отображаются подряд, только тогда они должны перейти к следующей строке.
for($i = 0; $i < $counter; $i )
{
$path = "http://verfix.com/playground_app/assets/images/upload/".$data['inspection'][$i]->image;
$toolcopy .= '<tr style"height:350px;">
<td style="width:100px;">
P-'.$data['inspection'][$i]->id.'
</td>
<td style="width:420px;">
<img src="'.$path.'" width="420" height="220">
</td>
</tr>';
}
$toolcopy .= '</table>[![enter image description here][1]][1]
Спасибо за любую помощь.
Ответ №1:
Попробуйте с этим кодом, он должен сделать свое дело.
$toolcopy = '<table>';
for($i = 0; $i < $counter; $i )
{
$path = "http://verfix.com/playground_app/assets/images/upload/".$data['inspection'][$i]->image;
if($i === 0 || $i % 2 === 0) {
if($i > 0) $toolcopy .= '</tr>';
$toolcopy .= '<tr style"height:350px;">';
}
$toolcopy .= '
<td style="width:100px;">
P-'.$data['inspection'][$i]->id.'
</td>
<td style="width:420px;">
<img src="'.$path.'" width="420" height="220">
</td>';
}
$toolcopy .= '</tr>';
$toolcopy .= '</table>';[![enter image description here][1]][1]
Он помещает два изображения в два отдельных элемента TD в одном и том же TR, следующие два изображения в следующей строке и так далее.