Arrays in checkbox value php mysql

0

I have the following code:

<thead>
 <tr>
  <th data-toggle="true"> Usuario </th>
  <?php 
    $consulta="SELECT * FROM etapas_lab WHERE id_cliente = '$id_us'"; 
        $ejecutar_consulta = $conexion->query($consulta); 
        $nomx = array();
        while ($registro = $ejecutar_consulta->fetch_assoc()){ 
         $nom = utf8_encode($registro["nombre"]);
         $nomx[] = $registro["id"];
         echo '<th>'.$nom.' </th>';
        } 
  ?>
 </tr>
</thead>

<tbody>
<?php 
    $consulta="SELECT * FROM users WHERE id_cliente = '$id_us'"; 
    $ejecutar_consulta = $conexion->query($consulta);                                       
     while ($registro = $ejecutar_consulta->fetch_assoc()){ 
      $nom_user = utf8_encode($registro["nombres"]);
      $ape_user = utf8_encode($registro['apellidos']);

    echo '<tr>';
    echo '<td>'.$nom_user.' '.$ape_user.' </td>';

    $arr_length = count($nomx); 

    for($i=0;$i<$arr_length;$i++){ 

    echo '<td><input type="checkbox" class="js-switch" name="permiso[]" 
    data-color="#99d683" data-secondary-color="#f96262" data-size="small" 
    value='--> AQUI DEBEN IR LOS ARRAYS <--' /> </td>';

    }                                                                           
echo '</tr>';   

} 
?>

</tbody>

What the first part of the code does (in the thead), calls names of processes that are listed in the head of the html table. The second part, counts the number of records (in the for) of my BD and puts a ckeckbox for each record to each user created in the BD. In the following image, it looks like it is:

Now, my problem is how to send the id of each process (casting, die cutting, etc) along with the id of the user through the value of the checkbox when the checkbox is clicked (I am using js-switch). It should be noted that the process id comes from the first query and the user id of the second query. As always, grateful for any help and / or guidance in this regard. Greetings to all.

    
asked by maha1982 18.05.2018 в 20:27
source

1 answer

0

If the array is being built well, you can write the second part of the code like this:

foreach($nomx as $item){
    echo '<td>
              <input type="checkbox" class="js-switch" name="permiso[]" 
                     data-color="#99d683" 
                     data-secondary-color="#f96262" 
                     data-size="small" value="'.$item.'" />
          </td>'; 
}
    
answered by 23.05.2018 / 22:57
source