I’m very new to programming and have an assignment that i need help with. I need to use my foreach loop in “index.php” to iterate over some data. It should use the HTML ‘blueprint’ from “layout_tabelleninhalt.html” for every single row and show the entire table in “layout_main.html”.
My index.php file:
$previous="";
$gesamttabelle ="";
foreach( $anzahlmonate as $monat => $Farbe ) {
foreach($Farbe as $Farbe => $anzahl){
$tabellen_template = file_get_contents('layout_tabelleninhalt.html');
if ($previous == $monat)
{
echo "" ;
}
else
{
echo $monat;
}
echo $Farbe ;
echo $anzahl ;
$previous = $monat;
$gesamttabelle .= $tabellen_template;
}
}
$content = file_get_contents ( 'layout_main.html');
$content = str_replace ( '{DATUM_VON}' , $post_datum_von , $content );
$content = str_replace ( '{DATUM_BIS}' , $post_datum_bis , $content );
$content = str_replace ( '{ANZAHL}' , $post_anzahl , $content );
$content = str_replace ( '{TABELLENINHALT}' , $tabellen_template , $content );
$content = str_replace ( '{FARBE}' , $Farbe , $content );
$content = str_replace ( '{ANZAHL}' , $anzahl , $content );
$content = str_replace ( '{MONAT}' , $monat , $content );
[echo($content);][1]
The layout_main.html file:
<table>
<caption>Liste der Button-presses</caption>
<tr>
<th>Monat und Jahr</th>
<th>Farbe</th>
<th>Anzahl</th>
</tr>
{TABELLENINHALT}
</table>
The layout_tabelleninhalt.html file:
<tr>
<td> {MONAT} </td>
<td class="tabelle_links"> {FARBE} </td>
<td class="tabelle_rechts"> {ANZAHL} </td>
</tr>
This is an image of my output. As you can see, only the first row is filled. How can i get the rest of the data in the table? Sorry if i’m missing something this is my first post.
[1]: https://i.stack.imgur.com/jPFvh.jpg