Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML table with ueven cells elements in even rows ( colspan )
    text
    copied!<p>I am trying to built a very simple diagram or flow chart representation of buildings .</p> <pre><code>$floors = array( array( 'app_1','app_2','app_2_A' ), array( 'app_3','app_4','app_5'), array( 'app_6','app_7', 'app_8','app_9') , array( 'app_10','app_11', 'app_12','app_13') , array( 'app_14','app_15', 'app_16') , ); echo "&lt;table border='2'&gt;"; foreach ($floors as $floor ) { $total_app = count( $floor); echo "&lt;tr&gt;"; for($i = 0;$i &lt; $total_app; $i++){ echo "&lt;td colspan=" .$total_app. "&gt;"; echo $floor[$i] . ' ( ' . $total_app . ' ) '; //brackets only for debug echo "&lt;/td&gt;"; } echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; </code></pre> <p>The result is :</p> <p><img src="https://i.stack.imgur.com/rSd6O.png" alt="Resultingtable"></p> <p>Problem is : The client wants all the rows to be of equal width , and not all the floors has the same number of apartments.</p> <p>So I thought I will use 'colspan'. ( in code <code>echo "&lt;td colspan=" .$total_app. "&gt;";</code> )</p> <p>Problem (2) : The script needs to work on 100´s of different buildings, so anything less than a full dynamic calculation for the 'colspan' will not work.</p> <p><code>Colspan</code> , as I understand it , is actually relative to the max number of cells i have ( the row with largest number of elements ).</p> <p>If that is true , then I need to know which array element ( floor ) has the highest count ( apartments ) - and then set this as the header - but I am not sure how to do it.</p> <p>so </p> <ol> <li><p>how can I count the elements inside the nested array and compare them to see the "most populated floor" </p></li> <li><p>having done that - how can I calculate the <code>colspan</code> for each floor´s row of apartments in relation to that max. ( <code>colspan</code> can have only int() and not fractions or percentage )</p></li> <li><p>A building is thought of as going from bottom to top, where as a table from top to bottom, so I need to flip the array , but keep the calculations of 'colspan'</p></li> <li><p>last but not least - I might be looking at this all wrong and there might be an easier way to achieve the wanted result ( maybe divs? ) - but I can not see one now - so if one exist - please do 'slap' me and show me the way ..</p></li> </ol> <p><strong>EDIT I</strong></p> <p>Like Said before : the solution must be flexible for all configurations : Example :</p> <pre><code>$floors = array( array( 'app_1','app_2','app_2_A','app_2_B','app_2_C', 'app_2_D'), array( 'app_3','app_4','app_5'), array( 'app_6','app_7') , array( 'app_10','app_11', 'app_12','app_13') , array( 'app_14') , ); </code></pre> <p>So any attempt to "hardcode" calculations of colspan will fail.. I need the Rows (floors) to be equal in width, and for the cells ( apartments ) to fill each row to full in such a way that if for example I have 2 apartments ,each will be 50% in width, if I have 4 apartments ,each will be 25% , 3 apartments - 33% and so on .</p> <p>The question is how to achieve that with <code>colspan</code> if possible, or with any other method ..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload