Selection of checkbox with value equal to the values of the POST

0

I take care that when opening the list of chekboxes, the checkboxes are automatically selected with the same id that I bring from an array

<?php          $id=0;
                    while ($clientes = pg_fetch_object($Cat))
                    {

                        if ($numfila == 0){ $class = "alt"; $numfila = 1; } else { $class = ""; $numfila = 0; }
                            echo "<tr class'".$class."' style=\"height: 5px;\">";

                                echo "<td align='center'>".$clientes->num_suc."</td>";
                                echo "<td align='left'>".$clientes->nom_suc."</td>";

                                //if ($clientes->sucursal = 0)
                             //  $asignada = array("$asignadas");
                                if (in_array($clientes->sucursal,$asignadas)){
                                    echo "<td align='center'> <input type='checkbox' name='cod[]' checked value='".$clientes->folio."'/>";
                                else
                                    echo "<td align='center'> <input type='checkbox' name='cod[]'  value='".$clientes->folio."'/>";


                            echo "</tr>";
                            $id=$id+1;
                    }
                    if( $id == 0 )
                        echo "Sin Sucursales Para Asignar"


      ?>
    
asked by Lmad99 18.08.2017 в 02:33
source

1 answer

0

You should have a table called a branch, then make a select * From branch with it you would get all the names of your branches.

   while($sucursales = pg_fetch_object($sur)){ 
         if ($sucursales->folio==$clientes->folio){ // clientes esta declarada arriba en tu codigo.
           echo "<td align='center'>'".$clientes->nombre."'<input type='checkbox' name='cod[]' checked value='".$clientes->folio."'/>";
          }else{
            echo "<td align='center'>'".$sucursales->nombre."'<input type='checkbox' name='cod[]'  value='".$sucursales->folio."'/>"; 
            }
            echo "</tr>";
            $id=$id+1;
    }

I do not see the name of the branch because the correct thing is that you had a customer table for another branch so you would get by inner join the branch ID as well as the name of the branch, your problem is with this if, when compiling your code only it should show the selected fields, what I understood is that you want to make a difference and see the selected ones as those that do not

    
answered by 18.08.2017 в 04:55