Link to home
Start Free TrialLog in
Avatar of Fernanditos
Fernanditos

asked on

Nested repeat region in 3 columns

Hi,

I have a normal nested repeat list (see attachment image).

It comes in just one table column.

How can with this CODE  to have this list split in 3 columns instead of 1 column?

Please GURU requiered,
thanks.


mysql_select_db($database_lawyers_conn, $lawyers_conn);
$query_master1category_cat = "SELECT * FROM category_cat ORDER BY name_cat";
$master1category_cat = mysql_query($query_master1category_cat, $lawyers_conn) or die(mysql_error());
$row_master1category_cat = mysql_fetch_assoc($master1category_cat);
$totalRows_master1category_cat = mysql_num_rows($master1category_cat);
 
mysql_select_db($database_lawyers_conn, $lawyers_conn);
$query_detail2subcategory_sub = "SELECT * FROM subcategory_sub WHERE idcat_subcat=123456789 ORDER BY name_subcat";
$detail2subcategory_sub = mysql_query($query_detail2subcategory_sub, $lawyers_conn) or die(mysql_error());
$row_detail2subcategory_sub = mysql_fetch_assoc($detail2subcategory_sub);
$totalRows_detail2subcategory_sub = mysql_num_rows($detail2subcategory_sub);
 
CODE:
 
<table border="1">
  <tr>
    <?php
  do { // horizontal looper version 3
?>
      <td><?php echo $row_Recordset1['name_cat']; ?></td>
      <?php
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    if (!isset($nested_Recordset1)) {
      $nested_Recordset1= 1;
    }
    if (isset($row_Recordset1) && is_array($row_Recordset1) && $nested_Recordset1++ % 3==0) {
      echo "</tr><tr>";
    }
  } while ($row_Recordset1); //end horizontal looper version 3
?>
  </tr>
</table>

Open in new window

screenshot-14281-62.47.240.240.png
Avatar of HainKurt
HainKurt
Flag of Canada image

pseudo code...
step = ceiling(total rec / 3)
 
function Write_section(n)
  your existing logic here, but filter main records ((n-1)*step) + 1 .. n*step
end
 
<table>
<tr>
  <td>
 
    write_section(1)
 
  </td>
</tr>
<tr>
  <td>
 
    write_section(2)
 
  </td>
</tr>
<tr>
  <td>
 
    write_section(3)
 
  </td>
</tr>
</table>

Open in new window

Avatar of Fernanditos
Fernanditos

ASKER

Hi

I'm sorry this is the right code to make the nested repeat region in 1 column.

But, I really can't make your solution work.

Could you please make the example using the real code ?

Please, thanks.

 
<table border="1">
  <?php do { ?>
    <tr>
      
      <td><b><?php echo $row_master1category_cat['name_cat']; ?></b></td>
    </tr>
    <?php
  if ($totalRows_master1category_cat>0) {
    $nested_query_detail2subcategory_sub = str_replace("123456789", $row_master1category_cat['id_cat'], $query_detail2subcategory_sub);
    mysql_select_db($database_lawyers_conn);
    $detail2subcategory_sub = mysql_query($nested_query_detail2subcategory_sub, $lawyers_conn) or die(mysql_error());
    $row_detail2subcategory_sub = mysql_fetch_assoc($detail2subcategory_sub);
    $totalRows_detail2subcategory_sub = mysql_num_rows($detail2subcategory_sub);
    $nested_sw = false;
    if (isset($row_detail2subcategory_sub) && is_array($row_detail2subcategory_sub)) {
      do { //Nested repeat
?>
      <tr>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row_detail2subcategory_sub['name_subcat']; ?></td>
      </tr>
      <?php
      } while ($row_detail2subcategory_sub = mysql_fetch_assoc($detail2subcategory_sub)); //Nested move next
    }
  }
?>
    <?php } while ($row_master1category_cat = mysql_fetch_assoc($master1category_cat)); ?>
</table>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernanditos
Fernanditos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial