Hello everyone) through this code information about the goods is displayed. There are sections on products in which there are 30 checkboxes and they are displayed in one vertical list (it’s scary not nice), I would like it to be displayed in 3 columns .. tell me how?

<?php if ( !defined('ABS_PATH') ) { exit('ABS_PATH is not loaded. Direct access is not allowed.'); } ?> <table class="sss"> <tbody> <?php $hide_empty = osc_get_preference('hide_empty', CA_PLUGIN_NAME); foreach ($fields as $field): $value = Attributes::newInstance()->getValue($item_id, $field['pk_i_id']); if (!empty($hide_empty) && 'hide' == $hide_empty) { if ('checkbox' != $field['s_type'] && '' == trim($value)) { continue; } } if ($field['s_type'] == 'checkbox'){ if($value != 'checked') continue; else $value = ''; } ?> <tr class="ddd"> <td class='detail_label'><?=$field['s_label']?></td> <td class='detail_label1'><?=$value?></td> </tr> <?php endforeach; ?> </tbody> </table> <?php //END 
  • it is probably necessary to divide the list into 2 (3) parts and in a line ( <tr>...</tr> ) to output 2 (3) list items at once. - aleksandr barakin
  • yes it is here that is necessary .. but how? - Ivan

3 answers 3

You can start from the following example

 <?php $filename = range(1, 12); // Вычисляем количество элементов в массиве $total = count($filename); // Количество столбцов в таблице $numcols = 3; // Вычисляем количество строк $number = (int)($total / $numcols); if((float)($total / $numcols) - $number != 0) $number++; // Формируем промежуточный двумерный массив $arr = []; for($i = 0; $i < $number; $i++) { for($j = 0; $j < $numcols; $j++) { $arr[$i][$j] = $filename[$j*$number + $i]; } } // Выводим таблицу echo "<table>"; for($i = 0; $i < $number; $i++) { echo "<tr>"; for($j = 0; $j < $numcols; $j++) { echo "<td>".$arr[$i][$j]."</td>"; } echo "</tr>"; } echo "</table>"; 
     <table class="sss"> <tbody> <tr class="ddd"> <td class="detail_label">рядом метро</td> <td class="detail_label1"></td> </tr> <tr class="ddd"> <td class="detail_label">благоустроенный двор</td> <td class="detail_label1"></td> </tr> 

    what is displayed on the result

    • Please supplement this information with your question (link under the word “edit”), and this “answer”, which is not the answer, please delete (link under the word “delete”). - aleksandr barakin

    The easiest way is to use the CSS property columns . Examples and explanations on the link above. On the habr .

     #example{ -webkit-columns: 200px 3; -moz-columns: 200px 3; columns: 200px 3; } 
     <div id='example'> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> <input type='checkbox' /><br /> </div> 

    Feeddle

    UPD:

    In table 30 boxes it is easier to place by changing the generation, increasing the number of cells in a row.

    It is possible to invent bicycles such as checks for length / quantity / metaphysical_properties, rebuild the table in accordance with the rules, but this will not be approved by the kosher, only Hindus may allow it. Something like this:

     <table class="sss"> <tr class="ddd"> <td class="detail_label">рядом метро</td> <td class="detail_label1"></td> <td class="detail_label">благоустроенный двор</td> <td class="detail_label1"></td> </tr> 
    • Thanks for the tips, BUT I have everything in the table, it would be desirable for me for the table (as I understand it is necessary to divide in the code itself), and not css - Ivan
    • Without the source data is difficult to recreate the page. I have no idea what will happen after the generation, please give a piece of the already created table. - user31688
    • @ Ivan, Updated the answer. - user31688 pm