Hi I think this is just a syntax problem, but I might be doing something PHP isn’t designed to do.
I’m trying to draw an HTML table, using an array to populate the table. The headers for example.
Where $headers is an array of headers I have attempted:
$html_table = '
<table border="1" cellspacing="0" cellpadding="2">
<tr>
foreach($headers as $header)
{
echo "<th> $header </th>";
}
</tr>
';
The idea being to generate:
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
...
<th>Heading 99</th>
</tr>
Simply by later asking for
$html_table
Suffice is to say at the moment I get a single headed column with “$header” in it, becuase the loop is not running inside the variable equation.
The reason I’m storing the HTML as a variable like this is because I want to concatenate (usage?) it with other generated html, i.e.
$html_table .= '</table>';
later on (of course the actual bit in the middle is more complicated, to do with retreiving data from databases to populate the table.
Where am I going wrong? Thanks
take the foreach out of the quotes