php - How to put values without repeating inside a table -


i have problem, need put different values inside table , not know how make structure.
these values in database:

|--------------|------------|-----------|----------| |  id_r_a_p_f  |  id_param  |  id_frec  |  value1  | |--------------|------------|-----------|----------| |       1      |   param1   |   frec1   |        | |--------------|------------|-----------|----------| |       2      |   param2   |   frec1   |   b      | |--------------|------------|-----------|----------| |       3      |   param3   |   frec1   |   c      | |--------------|------------|-----------|----------| |       4      |   param4   |   frec1   |   d      | |--------------|------------|-----------|----------| |       5      |   param1   |   frec2   |   e      | |--------------|------------|-----------|----------| |       6      |   param2   |   frec2   |   f      | |--------------|------------|-----------|----------| |       7      |   param3   |   frec2   |   g      | |--------------|------------|-----------|----------| |       8      |   param4   |   frec2   |   h      | |--------------|------------|-----------|----------| 

and want in my view

|--------------|------------|-----------| |     param    |   frec1    |   frec2   | |--------------|------------|-----------| |     param1   |          |   e       | |--------------|------------|-----------| |     param2   |   b        |   f       | |--------------|------------|-----------| |     param3   |   c        |   g       | |--------------|------------|-----------| |     param4   |   d        |  h        | |--------------|------------|-----------| 

not matter result same, param repeat instaed of diferent.

i catch de value fron database ok, not know how put in style in view. let view code if work anything.

<table>    <tbody>       <tr>          <td> param </td>              <?php                   $cont_frec = 0;                      foreach ($query_frec->result() $frec) {              ?>               <td>             <?php echo $frec->frec; ?>          </td>              <?php                 $cont_frec++;              }// end foreach frec              ?>       </tr> <?php     $previous_frec = '';       ($rel = 0; $rel < $cont_eval_x_frec; $rel++) {          if ($prev_param != $list_eval_x_frec[$rel]['id_param']) {            ?>            <tr>               <td>                   <?php echo $list_eval_x_frec[$rel]['id_param']; ?>                  </td>               <?php             }              $previous_frec != $list_eval_x_frec[$rel]['id_frec'];             ?>             <td>                 <?php echo $list_eval_x_frec[$rel]['value_1']; ?>             </td>              <?php           }// rel           ?></tr>   </tbody> </table> 

well not experienced php coder out there approach first build array query this:

$table_frec = array(); while($row = $query_frec->fetch_assoc()){   $table_frec[$row['id_param']][$row['id_frec']] = $row['value1'] } 

this give array looks like:

$table_frec {      [param1]=>{        [frec1]=>"a"        [frec2]=>"b"     }     [param2]=>{        [frec1]=>"c"        [frec2]=>"d"     }     ... } 

then can build table using array.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -