Include data through a Mysql / PHP explode

0

I have the following table:

ButIneedtoincludethematerialswithintherespectivefieldsofthedayoftheweekthatreflectstheschedules.Forthis,I'musing02methodsthatcreatetheimagebelow:

publicfunctioncadastrarHEscolas($idEscolas,$idGrades){...$this->comboboxGrade($jmVisualizar->IdHorarios,$idEscolas);...}publicfunctioncomboboxGrade($idHorarios,$idEscolas){$sqlListar=mysqli_query($this->conexao,"SELECT * FROM pe_materias WHERE IdEscolas = '".$idEscolas."';");

    $listar = "<select name='Materias[]' id='materias' class='form-control'>";
        $listar .= "<option value='Selecione'>Matéria</option>";  
        while($jmListar = mysqli_fetch_object($sqlListar)){
              $listar .= "<option value='".$jmListar->Materias."_".$idHorarios."'>".$jmListar->Materias."</option>";
         }  
         $listar .= "</select>";
         return $listar;  
}

So far so good, but for me to store inside the IdHorarios, I include in the second method, in the option attribute the following line:

$listar .= "<option value='".$jmListar->Materias."_".$idHorarios."'>".$jmListar->Materias."</option>";

The above code returns the Id of the Schedules table and the Matter, separated by the underline.

And when I click on register, I use the method below to register in the database:

    public function cadastrarGradeMaterias($materias){

   // $materias me retorna portugues_1, matematica_1, fisica_2, etc.

       for($m = 0; $m < count($materias); $m++){ 
           $mat = explode("_",$materias);

        $sqlCadastrar = mysqli_query($this->conexao,"UPDATE tabela SET Segunda - '', Terca = '', Quarta = '', Quinta = '', Sexta = '', Sabado = '' WHERE IdHorario = ''");
       }
    }

Here's the problem. How would I do to give an explode and include within the query the selected fields and their respective ID?

    
asked by anonymous 21.07.2017 / 02:25

1 answer

1

There is more detail to note just defined it like this:

       <select name='Materias[]' id='materias' class='form-control'>

I asked to rename, to also have the understanding of the day there in the update routine. But if you are defining a type list in your html, name=MateriasSegunda[] there in your php code will receive an array of values of the select that has that name in the case following your image values select 07:00 - 07:40, 08 : 00 - 08:40 and 09:00 - 09-40 so this explode line will not work:

  $materias_segunda = $_POST['MateriasSegunda'];
  $mat = explode("_",$materias_segunda);

I would have to run the explode like this:

  $materias_segunda = $_POST['MateriasSegunda'];
  foreach($materias_segunda as $materia_hora){
     $mat = explode("_",$materia_hora); 
     $materia_segunda[]        = $materia_hora[0]; 
     $materia_segunda_idHora[] = $materia_hora[1]; 
  }

That is, $_POST['MateriasSegunda'] is an array containing the materials and idHarario on Monday.

After doing this on all days of the week, and in possession of the values of the day time and matter, you could carry out your update.

Improve my example I wrote quickly for understanding only.

    
21.07.2017 / 03:36