how insert foreach function in html?
up vote
0
down vote
favorite
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?
php html
add a comment |
up vote
0
down vote
favorite
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?
php html
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.
– Magnus Eriksson
Nov 12 at 7:00
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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?
php html
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?
php html
php html
asked Nov 12 at 6:56
Krisanda Triputro
31
31
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.
– Magnus Eriksson
Nov 12 at 7:00
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21
add a comment |
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.
– Magnus Eriksson
Nov 12 at 7:00
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (
?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.– Magnus Eriksson
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (
?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.– Magnus Eriksson
Nov 12 at 7:00
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
In your foreach
, rather than echo
ing the value, build it up into a string
(adding each part with .=
) which you can then insert into your larger HTML...
$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();
$htmlTable = "";
foreach ($coaTitle as $coa) {
$htmlTable .= '<tr>';
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
// Continue adding fields using `$coa['FIELD NAME']` and $htmlTable .= ...
$htmlTable .= '</tr>';
}
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>'
.$htmlTable.'<br><br>
</table>
</html>';
return $detailJournal;
}
You just need to use the line
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
as a template to add in the other columns.
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
add a comment |
up vote
0
down vote
try this:
$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>'.$coa[0]['COA_CODE'].'</span></td><br>';
}
in foreach($coaTitle as $coa) you must use $coa instead $coaTitle
add a comment |
up vote
0
down vote
if you want to add php code in html file then, you can add directly by adding php tag, and save file with .php extension
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<?php
foreach ($coaTitle as $coa) {
?>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coa[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>
<?php
}
?>
</table>
</tr>
</table>
</html>
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening<?php
within the output?
– Nico Haase
Nov 12 at 7:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257198%2fhow-insert-foreach-function-in-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
In your foreach
, rather than echo
ing the value, build it up into a string
(adding each part with .=
) which you can then insert into your larger HTML...
$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();
$htmlTable = "";
foreach ($coaTitle as $coa) {
$htmlTable .= '<tr>';
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
// Continue adding fields using `$coa['FIELD NAME']` and $htmlTable .= ...
$htmlTable .= '</tr>';
}
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>'
.$htmlTable.'<br><br>
</table>
</html>';
return $detailJournal;
}
You just need to use the line
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
as a template to add in the other columns.
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
add a comment |
up vote
1
down vote
accepted
In your foreach
, rather than echo
ing the value, build it up into a string
(adding each part with .=
) which you can then insert into your larger HTML...
$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();
$htmlTable = "";
foreach ($coaTitle as $coa) {
$htmlTable .= '<tr>';
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
// Continue adding fields using `$coa['FIELD NAME']` and $htmlTable .= ...
$htmlTable .= '</tr>';
}
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>'
.$htmlTable.'<br><br>
</table>
</html>';
return $detailJournal;
}
You just need to use the line
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
as a template to add in the other columns.
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
In your foreach
, rather than echo
ing the value, build it up into a string
(adding each part with .=
) which you can then insert into your larger HTML...
$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();
$htmlTable = "";
foreach ($coaTitle as $coa) {
$htmlTable .= '<tr>';
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
// Continue adding fields using `$coa['FIELD NAME']` and $htmlTable .= ...
$htmlTable .= '</tr>';
}
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>'
.$htmlTable.'<br><br>
</table>
</html>';
return $detailJournal;
}
You just need to use the line
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
as a template to add in the other columns.
In your foreach
, rather than echo
ing the value, build it up into a string
(adding each part with .=
) which you can then insert into your larger HTML...
$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();
$htmlTable = "";
foreach ($coaTitle as $coa) {
$htmlTable .= '<tr>';
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
// Continue adding fields using `$coa['FIELD NAME']` and $htmlTable .= ...
$htmlTable .= '</tr>';
}
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>'
.$htmlTable.'<br><br>
</table>
</html>';
return $detailJournal;
}
You just need to use the line
$htmlTable .= '<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td><br>';
as a template to add in the other columns.
answered Nov 12 at 7:19
Nigel Ren
24.1k61832
24.1k61832
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
add a comment |
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
thanks for helping :D
– Krisanda Triputro
Nov 12 at 8:18
add a comment |
up vote
0
down vote
try this:
$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>'.$coa[0]['COA_CODE'].'</span></td><br>';
}
in foreach($coaTitle as $coa) you must use $coa instead $coaTitle
add a comment |
up vote
0
down vote
try this:
$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>'.$coa[0]['COA_CODE'].'</span></td><br>';
}
in foreach($coaTitle as $coa) you must use $coa instead $coaTitle
add a comment |
up vote
0
down vote
up vote
0
down vote
try this:
$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>'.$coa[0]['COA_CODE'].'</span></td><br>';
}
in foreach($coaTitle as $coa) you must use $coa instead $coaTitle
try this:
$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>'.$coa[0]['COA_CODE'].'</span></td><br>';
}
in foreach($coaTitle as $coa) you must use $coa instead $coaTitle
answered Nov 12 at 7:04
user10116577
1
1
add a comment |
add a comment |
up vote
0
down vote
if you want to add php code in html file then, you can add directly by adding php tag, and save file with .php extension
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<?php
foreach ($coaTitle as $coa) {
?>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coa[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>
<?php
}
?>
</table>
</tr>
</table>
</html>
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening<?php
within the output?
– Nico Haase
Nov 12 at 7:22
add a comment |
up vote
0
down vote
if you want to add php code in html file then, you can add directly by adding php tag, and save file with .php extension
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<?php
foreach ($coaTitle as $coa) {
?>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coa[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>
<?php
}
?>
</table>
</tr>
</table>
</html>
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening<?php
within the output?
– Nico Haase
Nov 12 at 7:22
add a comment |
up vote
0
down vote
up vote
0
down vote
if you want to add php code in html file then, you can add directly by adding php tag, and save file with .php extension
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<?php
foreach ($coaTitle as $coa) {
?>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coa[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>
<?php
}
?>
</table>
</tr>
</table>
</html>
if you want to add php code in html file then, you can add directly by adding php tag, and save file with .php extension
$detailJournal = '<!DOCTYPE html>
<html>
<table>
<tr>
<table border = 0 cellspacing = 0 cellpadding = 0 align = center>
<?php
foreach ($coaTitle as $coa) {
?>
<tr>
<td width=55><span style=font-size:10pt; line-height:19px; text-align:left>'.$coa['COA_CODE'].'</span></td>
<td width=170><span style=font-size:10pt; line-height:19px; text-align:center>'.$coa[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>
<?php
}
?>
</table>
</tr>
</table>
</html>
edited Nov 12 at 7:31
answered Nov 12 at 7:06
Poonam Navapara
18618
18618
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening<?php
within the output?
– Nico Haase
Nov 12 at 7:22
add a comment |
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening<?php
within the output?
– Nico Haase
Nov 12 at 7:22
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening
<?php
within the output?– Nico Haase
Nov 12 at 7:22
Please add some explanation to your code. Additionally, are you sure that it does anything good? Why is there an opening
<?php
within the output?– Nico Haase
Nov 12 at 7:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257198%2fhow-insert-foreach-function-in-html%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
give the full html code. You already insert an output inside foreach loop.
– Zico
Nov 12 at 7:00
The easiest way would be by not putting the HTML in a PHP variable but to end the PHP block (
?>
), write your html (with any PHP you need, like usual), and then start the PHP block again. Otherwise, you need to concatenate your variable.– Magnus Eriksson
Nov 12 at 7:00
i try insert php block ( ?> ) but it's not working, i try insert function in model it's not working too
– Krisanda Triputro
Nov 12 at 7:08
What have you tried? What are you looking for - what is not working with the given code?
– Nico Haase
Nov 12 at 7:21