Jump to content

Recommended Posts

i create a table from a multilevel array wich is loaded from a database and processed, the problem is that the data loaded will some times have gaps in the position that it should be inside a certain html column...

i can´t quite explain it so i'll give an example.

 

[0] => array(
	[name] => john
	[id]   => 2
	[data] => array([data1] => array(
					 [0] => array(
					 	      [value] => 10
				         	      [order] => 1
					             )
					 [1] => array(
					 	      [value] => 5
				         	      [order] => 3
					             )

		        [data3] => array([0] => array(
						      [value] => 30
				         	      [order] => 1
						     )
		       )
     )

 

| id | Name |   Data1  | Data2 | Data3 |
| 2  | john | 10 | | 5 |       |   | 2 |
|other varied values...|

 

inside john>data1 there wasnt a order 2 specified so it should create an empty <td> in the correspondent position

and then adapt the rest of the table so that there is always the same number of <td> under each colomn.

 

i managed to make that but the code is really really big and messy with a lot of loops, it is currently using too much processing power to achieve that.

 

so i came here to ask if you guys have any suggestion that could help ease this process :)

Link to comment
https://forums.phpfreaks.com/topic/201693-generating-html-table-with-data-gaps/
Share on other sites

//code to select data, and query stored to $q

echo '<table>';

echo '<tr><td>headings</td>.........</tr>';

while ($r=mysql_fetch_assoc($q)){

echo '<tr>';

foreach ($r as $value){

if(is_array($value){

//do array stuff, the inner table, i would recommend put all foreach in a recursive function

}

echo '<td>'.(empty($value)?' ':$value).'</td>';

}

echo '</tr>';

}

echo '</table';

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.