0





284
1

I have a list product

Invoice No. | Product Name | Quantity
INV001      |    iPhone    |    1 
INV001      |    iPad      |    2
INV001      |    iPod      |    1 
INV002      |    iMac      |    2
INV002      |    iPhone    |    1 

After fetch all data to array, how ideas to create table auto rowspan when Invoice No. same value.

Invoice No. | Product Name | Quantity
    INV001  |    iPhone    |    1 
            |    iPad      |    2
            |    iPod      |    1 
    INV002  |    iMac      |    2
            |    iPhone    |    1 

<table>
   <tr>
      <th>Invoice No.</th>
      <th>Product Name</th>
      <th>Quantity</th>
   </tr>
   <tr>
      <td rowspan="3">INV001</td>
      <td>iPhone</td>
      <td>1</td>
   </tr>
   <tr>
      <td>iPad</td>
      <td>2</td>
   </tr>
   <tr>
      <td>iPod</td>
      <td>1</td>
   </tr>
   <tr>
      <td rowspan="2">INV001</td>
      <td>iMac</td>
      <td>2</td>
   </tr>
   <tr>
      <td>iPhone</td>
      <td>1</td>
   </tr>
</table>
Question author Hai-truong-it | Source

0


1
$data = // query result
$last_key = null;
$dum_arr = array();
foreach ($data as $key => $row) {
   if($row->name == $last_key) {
      $dum_arr[] = $key;
   }

   if(!in_array($key, $dum_arr)) {
       // echo rowspan here...
   }

   $last_key = $row->name;
}

Ask about this question here!