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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.