I have a view file that uses a foreach 2 times, the first time works but the second foreach doesn't do anything.
<?php
echo '<table><tr>'; #begin table
foreach ($query->list_fields() as $field) { #generate table headers
printf("<th>%s</th>\n", $field);
}
print('<th> </th></tr>'); #exra whitespace and end table row
print('<tr>'); # start new row for table data
foreach ($query->list_fields() as $data) { #generate table data
printf("<td>%s</td>\n", $data);
}
print('</tr></table>');
so the tableheaders are shown see the sourcecode:
How can I arrange that the second foreach is going to work?
Going along with what the comments have said, this is the solution:
$my_data = $query->list_fields();
foreach($my_data as $field) { #generate table headers
printf("<th>%s</th>\n", $field);
}
foreach ($my_data as $data) { #generate table data
printf("<td>%s</td>\n", $data);
}