bocasz Posted May 14, 2010 Share Posted May 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201693-generating-html-table-with-data-gaps/ Share on other sites More sharing options...
greatstar00 Posted May 14, 2010 Share Posted May 14, 2010 //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'; Quote Link to comment https://forums.phpfreaks.com/topic/201693-generating-html-table-with-data-gaps/#findComment-1058080 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.