Jump to content

foreach into table


Nodral

Recommended Posts

Hi All

 

Please see code below.  I cannot get my table to produce correctly.  I have a multidimensional array $data['id']['fieldid']=$row['content']

I want this to loop through and create a new line in a table for each sub-array.  hence the table would look like this.

 

(id1 in this row) 

field1 content 

field2 content 

field3 content 

field4 content 

(id2 in this row) 

field1 content 

field2 content 

field3 content

field4 content 

(id3 in this row) 

field1 content 

field2 content 

field3 content 

field4 content 

(id4in this row) 

field1 content 

field2 content 

field3 content 

field4 content 

etc etc.  The table can grow or shrink depending on the data I'm retrieving.

 

<table><font size="8">
<tr>
<?php
foreach ($header_out as $value){
echo "<td>$value</td>";
}
?>

</tr>
<?php
echo"<tr>";
foreach($data as $value){
$count++;
	foreach($value as $dataout){
	echo "<td>$dataout $count</td>";
}

}echo"</tr><tr>";
?>
</tr></font></table>

<?php } ?>

 

The header section works fine, but the double foreach loop seems to be where I'm failing.

 

Any advice guys?

Link to comment
https://forums.phpfreaks.com/topic/234338-foreach-into-table/
Share on other sites

I seem to be able to either get all the content in column 1 of the table or all in 1 row for all id's.

 

I want each id on it's own line in the table.  I just don't seem to be able to get the <tr> tags to appear in the correct place when foreaching the info out.

Link to comment
https://forums.phpfreaks.com/topic/234338-foreach-into-table/#findComment-1204508
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.