I'm a newbie who's been looking for a solution regarding inserting a PHP foreach output in HTML,
there is my query code:
$qr = $this->db->query("select journalDetail.COA_CODE, COA_TITLE, COA_TYPE from t_journal_detail journalDetail left join r_coa coaTitle on journalDetail.coa_code=coaTitle.coa_code where journalDetail.JOURNAL_ID = '".$journalId."'");
$coaTitle = $qr->result_array();
foreach ($coaTitle as $coa) {
echo '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coaTitle[0]['COA_CODE'].'</span></td><br>';
}
and there is my html code:
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coaTitle[0]['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coaTitle[0]['COA_TITLE'].'</span></td>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:center>IDR</span></td>
<td width=81><span style=font-size:10pt; line-height:19px; text-align:right>'.$journalDetail[0]['ORIG'].'</span></td>
<td width=89><span style=font-size:10pt; line-height:19px; text-align:right>0</span></td>
<td width=89><span style=font-size:10pt; line-height:19px; text-align:right>'.$journalDetail[0]['SUM'].'</span></td>
</tr><br><br>
</table>
</html>';
return $detailJournal;
}
the question is how insert foreach in html?
?>), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.