Save/maintain checkbox status (selected or not selected) after closing the browser

Asked

Viewed 152 times

-1

I’m making a page that has a table with values coming from the database. It has 4 columns and more than 300 rows. A column has a checkbox for each row, the other has the name of an object and the other two columns have characteristics of that object. I need that after the person score one checkbox, it appears marked even if it closes the browser. This can be done in php?

<html>
<head></head>
<body>
<?php
  // INICIAR SESSÃO
  //=================================================================
  if (isset('$_SESSION'['msg'])) {
      echo $_SESSION['msg'];
      unset ($_SESSION['msg']);
  }
  
  
  // TRAZER DADOS DO BANCO
  //=================================================================
  $result_cruzamentos = "SELECT * FROM polo_pi_02";
  $resultado_cruzamentos = mysqli_query($conn, $result_cruzamentos);
  
  
  // EXIBIÇÃO DA TABELA
  //===================================================       
  echo '<div id="inicio" class="row valign-wrapper">';
      echo '<div id="admin" class="col s12 ">';
          echo '<form action="../php/action_handler.php" method="POST">';
              echo '<div class="center-align card material-table">';
                  echo '<div class="table-header">';
                      echo '<span class="table-title">GOIÁS SUL/ NORTE - FLUXO TARDIO</span>';
                      echo '<div class="actions">';
                          echo '<a href="#" class="search-toggle btn-flat nopadding"><i class="material-icons">search</i></a>';
                      echo '</div>';
                  echo '</div>';
                  echo '<table id="datatable" class="highlight display centered">';                               
                      echo '<thead>';
                          echo '<tr>';
                              echo '<th class="cor_0">Status</th>';                                    
                              echo '<th class="cor_0">Rank</th>';
                              echo '<th class="cor_0">Nome</th>';
                              echo '<td class="cor_1">PCC</td>';                                        
                          echo '</tr>';
                      echo '</thead>';


                      // TBODY
                      // ================================================================
                      echo '<tbody>';
                      // Armazena os dados da consulta em um array associativo
                      while($row_cruzamento = mysqli_fetch_assoc($resultado_cruzamentos)){
                          echo '<tr>';

                              // COLUNA 1: CHECKBOX
                              //--------------------------------------------------------------------------
                              echo '<td class="checkbox">';
                                 echo '<input type="checkbox" id="check_id_'.$row_cruzamento['pagina_cruz'].'" value="'.$row_cruzamento['pagina_cruz'].'" name="checados[]" class="filled-in" />';
                                 echo '<label for="check_id_'.$row_cruzamento['pagina_cruz'].'"></label>';
                              echo '</td>';  

                              // COLUNA 2: RANKING
                              //-------------------------------------------------------------------------                         
                              echo '<td>'.$row_cruzamento['cruz_id'].'</td>';

                              // COLUNA 3: NOME
                              //--------------------------------------------------------------------------
                              echo '<td class="large">';
                                  echo '<div>';
                                      echo '<p>'.$row_cruzamento['g1'].'</p>';
                                      echo '<p>'.$row_cruzamento['g2'].'</p>';
                                  echo '</div>';
                              echo '</td>';

                              // COLUNA 4: NOTA
                              //------------------------------------------------------------------------                          
                              echo '<td>';
                                  echo '<div class="change_color">';
                                      echo '<p id="g1fenbvpcc">'.$row_cruzamento['g1_fen_bv_pcc_nota'].'</p>';
                                      echo '<p>'.$row_cruzamento['g2_fen_bv_pcc_nota'].'</p>';
                                  echo '</div>';
                              echo '</td>';                                    
                          echo '</tr>';
                      }
                      echo '</tbody>';
                  echo '</table>';
              echo '</div><!-- END MATERIAL-TABLE -->';
  
              // BOTÃO PARA SALVAR ESTADO DO CHECKBOX
              echo '<center>';
              echo '<div>';
                  echo '<a class="save waves-effect waves-light btn indigo darken-4 tooltiped" title="Salva o estado de seleção dos cruzamentos"><input type="submit" value="SALVAR"></a>';            
              echo '</div>';
              echo '</center>';
    
              echo '</form>';
          echo '</div><!-- END COL s12 -->';
      echo '</div><!-- END ROW -->';
  
  ?>
  </body>
  <html>

  • 1

    Put your code to help her better. Follow this idea of yours. You can do this: When a user clicks on the checkbox vc Ubmit the form or via ajax, vc updates your database with a flag (checkbox marked or not). With this, even closing the browser you will have the information in the database and can return the value of the check marked after.

  • 1

    "marked even if it closes the browser", in this case you need to save in some repository, a database for example, or in the user’s computer cookies, but this can be deleted, so the best option would be to know in a database.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.