Jump to content

gmc1103

Members
  • Posts

    251
  • Joined

  • Last visited

Posts posted by gmc1103

  1. 27 minutes ago, requinix said:

    You're using the htmlentities function when you should not be.

    1. You should be using htmlspecialchars instead when outputting something safely to HTML. htmlentities is unnecessary, and if you "need" it to make something look correct then that means you have other character encoding problems that need to be solved.
    2. You should only be doing that at the very last moment right when you're doing the output - never before, or else you'll run into problems such as your current issue.

    Thanks for your reply

     

    htmlentities where??

    before saving to DB i'm sure the data is correct

    $this->db->query('INSERT INTO tblatividades (atividade, objetivos, haveClasses, participantes, grupoAlvo, orcamento, dataAtividade, hora, local, idAnoEscolar, idProfessor, idProjeto, dataLancado, versao) 
                    VALUES (:atividade, :objetivos, :haveClasses, :participantes, :grupoAlvo, :orcamento, :dataAtividade, :hora, :local, :idAnoEscolar, :idProfessor, :idProjeto, NOW(),:versao)');
                    //Bind values
                    $this->db->bind(':atividade', $data['atividade']);
                    $this->db->bind(':objetivos', $data['objetivos']);
                    $this->db->bind(':haveClasses', $data['haveClasses']);
                    $this->db->bind(':participantes',$data['participantes']);
                    $this->db->bind(':grupoAlvo', $data['grupoAlvo']);
                    $this->db->bind(':orcamento', $data['orcamento']);
                    $this->db->bind(':dataAtividade', $dataAtividade);
                    $this->db->bind(':hora', $data['hora']);
                    $this->db->bind(':local', $data['local']);
                    $this->db->bind(':idAnoEscolar', $idAnoEscolar);
                    $this->db->bind(':idProfessor', $data['idProfessor']);
                    $this->db->bind(':idProjeto',$idProjeto);
                    $this->db->bind(':versao', $versao);
                    $turma = $data['idTurma'];
                    $idProfessores = $data['idProfessores'];
                    $idAtividade =$this->db->execute();

    $this->db->bind(':atividade', $data['atividade']);

    echo this, gives me "Participação"but saved as "Participaçã"

    The character set is the same for both tables and the collation either, so i don't get why this is happening

     

    This is my db connection

     

    <?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    setlocale( LC_ALL, "pt_PT.UTF-8");
    
    class Database {
        private $host = '';
        private $user = '';
        private $pass = '';
        private $dbname = '';
        private $charset = "";
    
        //Will be the PDO object
        private $dbh;
        private $stmt;
        private $error;
    
    
        public function __construct(){
    
    
    
            //Set DSN
            $dsn = "mysql:host=$this->host;dbname=$this->dbname;charset=utf8mb4";
            //Create PDO instance
            try{
                $this->dbh = new PDO($dsn, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES"'));
    
            }catch(PDOException $e){
                $this->error = $e->getMessage();
                echo $this->error;
            }
        }
    
        //Prepare statement with query
        public function query($sql){
            $this->stmt = $this->dbh->prepare($sql);
        }
    
        //Bind values, to prepared statement using named parameters
        public function bind($param, $value, $type = null){
            if(is_null($type)){
                switch(true){
                    case is_int($value):
                        $type = PDO::PARAM_INT;
                        break;
                    case is_bool($value):
                        $type = PDO::PARAM_BOOL;
                        break;
                    case is_null($value):
                        $type = PDO::PARAM_NULL;
                        break;
                    default:
                        $type = PDO::PARAM_STR;
                }
            }
            //echo $this->stmt->bindValue($param, $value, $type);
            $this->stmt->bindParam($param, $value, $type);
        }
    
        //Execute the prepared statement
        public function execute(){
            $info = $this->stmt->execute();
            $id = $this->lastIdInserted();
            if($id != 0){
                $info = $id;
            }
            else{
                if($info){
                    $info = true;
                }
                else{
                    $info = false;
                }
            }
            return $info;
        }
    
        //Return multiple records
        public function resultSet(){
            $this->execute();
            return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
        }
    
        //Return a single record
        public function single(){
            $this->execute();
            return $this->stmt->fetch(PDO::FETCH_ASSOC);
        }
    
        //Get row count
        public function rowCount(){
            return $this->stmt->rowCount();
        }
    
        public function lastIdInserted(){
            return $this->dbh->lastInsertId();
        }
    }

     

  2. Hello

     

    I'm having a problem regarding saving data into database

    I have 2 tables, one is keeping the character set defined, the other no

    So, in one table i put "Participação" and it is saved as "Participa&ccedil;&atilde;"

    The other table i put "Participação" and it is saved as "Participação".

    Both have the sames settings

    image.png.b7ec95c23212229532a1f7783321319f.png

     

    image.png.b40b32bfb9f45d2d48cc3dc956b64d88.png

     

    So any help what can it  be??

  3. Hello

    I'm trying to find the right solution to get only one record in my query but i'm getting 9 records.

    So when i'm inserting a new record in main main table (visitas) other data is inserted into 3 other tables (MN) like teachers, departments and classes names

    I'm using this query, and i'm using group concat, it works well whith classes (turmas) and departments(dpt) but with teachers names it gives 9 records

    3* classes, 2 departments and 3 teachers 

    The query

     

    select n.idvisita, n.destino, t5.nome, GROUP_CONCAT(t4.turma SEPARATOR ', ') as turmas,  GROUP_CONCAT(t3.departamento SEPARATOR ', ') as dpt,
           n.startDate,
           n.horaSaida,
           n.endDate,
           n.horaChegada,
           n.haveClasses,
           n.tipoTurma,
            n.PlanoOcupacaoAlunos,
            n.PlanoOcupacaoTurmas,
            n.TipoTransporte,
            n.CustoTransporte,
            n.TipoSeguro,
            n.CustoSeguro,
            n.TipoEstadia,
            n.CustoEstadia,
            n.total,
            n.TotalAluno,
            n.Financiamento,
           GROUP_CONCAT(t5.nome SEPARATOR ', ') as docentes
           from tblvisitas as n
    inner join tblvisitas_has_tblturmas as n1 on n.idvisita = n1.idvisita
    inner join tblturmas t4 on n1.idTurma = t4.idTurma
    inner join tblvisitas_has_tbldepartamentos tht on n.idvisita = tht.idvisita
    inner join tbldepartamentos t3 on tht.idDepartamento = t3.idDepartamento
    inner join tblvisitas_has_tblprofessores as t2 on n.idvisita = t2.idvisita
    inner join tblprofessores t5 on t2.idProfessor = t5.idProfessor
    inner join tblanoescolar t on n.idAnoEscolar = t.idAnoEscolar
    where n.idvisita = 20 and t.estado = 1
    GROUP by n.idvisita, n.destino, t5.nome, t4.turma, n.startDate, n.horaSaida, n.endDate, n.horaChegada, n.haveClasses, n.tipoTurma, n.PlanoOcupacaoAlunos, n.PlanoOcupacaoTurmas, n.TipoTransporte, n.CustoTransporte, n.TipoSeguro, n.CustoSeguro, n.TipoEstadia, n.CustoEstadia, n.total, n.TotalAluno, n.Financiamento

     

    The data in each MN tables

    tblvisitas_has_tbldepartamentos table

    idVisita idDepartamento

    20                 6
    20                 1

    tblvisitas_has_tblprofessores

    idVisita idProfessor

    20                 8
    20                 9
    20                 11
     

    tblvisitas_has_tblturmas

    idVisita idTurma

    20             10
    20             11
    20             23 
     

    When i execute the above query i get this

    The last column is the problem

    +--------+-------+-----------+------------+-------------------------------------------------------------------------+----------+---------+----------+-----------+-----------+------------------------------------+-------------------+-------------------+----------------------------+---------------+----------+-----------+-----------+------------+--------------+------------+----------------------------------+------------------------+
    |idvisita|destino|nome       |turmas      |dpt                                                                      |startDate |horaSaida|endDate   |horaChegada|haveClasses|tipoTurma                           |PlanoOcupacaoAlunos|PlanoOcupacaoTurmas|TipoTransporte              |CustoTransporte|TipoSeguro|CustoSeguro|TipoEstadia|CustoEstadia|total         |TotalAluno  |Financiamento                     |docentes                |
    +--------+-------+-----------+------------+-------------------------------------------------------------------------+----------+---------+----------+-----------+-----------+------------------------------------+-------------------+-------------------+----------------------------+---------------+----------+-----------+-----------+------------+--------------+------------+----------------------------------+------------------------+
    |20      |Lisboa |Justino    |A-CAL, A-CAL|Departament de Educação Pré-Escolar , Matemática e Ciências Experimentais|2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Justino, Justino        |
    |20      |Lisboa |Justino    |A-VP, A-VP  |Matemática e Ciências Experimentais, Departament de Educação Pré-Escolar |2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Justino, Justino        |
    |20      |Lisboa |Justino    |B-CAL, B-CAL|Matemática e Ciências Experimentais, Departament de Educação Pré-Escolar |2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Justino, Justino        |
    |20      |Lisboa |Teste      |A-CAL, A-CAL|Matemática e Ciências Experimentais, Departament de Educação Pré-Escolar |2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste, Teste            |
    |20      |Lisboa |Teste      |A-VP, A-VP  |Departament de Educação Pré-Escolar , Matemática e Ciências Experimentais|2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste, Teste            |
    |20      |Lisboa |Teste      |B-CAL, B-CAL|Matemática e Ciências Experimentais, Departament de Educação Pré-Escolar |2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste, Teste            |
    |20      |Lisboa |Teste final|A-CAL, A-CAL|Matemática e Ciências Experimentais, Departament de Educação Pré-Escolar |2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste final, Teste final|
    |20      |Lisboa |Teste final|A-VP, A-VP  |Departament de Educação Pré-Escolar , Matemática e Ciências Experimentais|2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste final, Teste final|
    |20      |Lisboa |Teste final|B-CAL, B-CAL|Departament de Educação Pré-Escolar , Matemática e Ciências Experimentais|2023-05-09|12:00:00 |2023-05-12|12:00:00   |Sim        |Cient&iacute;fico/Human&iacute;stico|Todas              |Todas              |Avi&atilde;o;Autocarro;Barco|2000           |Sim       |500        |Sim        |500         |3500.00 &euro;|83.00 &euro;|Escola;POCH;C&acirc;mara Municipal|Teste final, Teste final|
    +--------+-------+-----------+------------+-------------------------------------------------------------------------+----------+---------+----------+-----------+-----------+------------------------------------+-------------------+-------------------+----------------------------+---------------+----------+-----------+-----------+------------+--------------+------------+----------------------------------+------------------------+
    

     

  4. I'm trying to run a query but my outcome is not what i need. So the problem is: A user can be diretor and if this is the case he can see all activities from his department, and he can be user of another department too, in this case not director but only user. I have 8 departments each with one director, so the following query should give me the activities of the department and the activities of this particular user in other department:

    SELECT t1.idAtividade,
           t1.idProfessor,
           t2.Escola,
           t1.Atividade,
           t1.Periodo,
           t1.Mes,
           t1.haveClasses,
           t1.DataPrevista,
           t1.Destinatarios,
           t1.Orcamento,
           t1.PdfAtividade,
           t1.Avaliacao,
           t1.PdfAvaliacao,
           t1.idProfessor,
           p.Nome,
           d.Departamento,
           p2.Projeto,
           t1.idProjeto
    FROM atividades AS t1
             INNER JOIN professores p on t1.idProfessor = p.idProfessor
             RIGHT JOIN atividadesgrupos ag on t1.idAtividade = ag.idAtividade
             RIGHT JOIN departamentosatividades da on t1.idAtividade = da.idAtividade
             RIGHT JOIN departamentos d on da.idDepartamento = d.idDepartamento
             INNER JOIN escolas AS t2 ON (t2.idEscola = t1.idEscola)
             INNER JOIN anosescolares AS ae ON (t1.idAnoEscolar = ae.idAnoEscolar)
             INNER JOIN projetos p2 on t1.idProjeto = p2.idProjeto
    WHERE ae.Estado = 1 AND da.idDepartamento = 8
    ORDER BY (t1.idProfessor = 60) DESC, t1.idProfessor;

     

    This query is not working because the department have 22 activities but this user (idProfessor) has 5 in this department and 14 more in another department (defined by idGrupo)

    I think i will need a subquery right?

  5. Hi Kicken

     

    Thank's for helping me.

    You are right about your explanation.

    I have followed your explaination and tried your code but there is an error, the var_export of the code provided gives me this array

     

    array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-09-22',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-09-23',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-09-29',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-09-30',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-10-06',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-10-07',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-10-13',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-10-14',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '718',
      'idCpModulos' => '318',
      'dataAula' => '2020-10-20',
      'tempos' => '1',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-10-20',
      'tempos' => '3',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-10-27',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-10-28',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-03',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-04',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-10',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-11',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-17',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-18',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-24',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-11-25',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-12-02',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-12-09',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-12-15',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2020-12-16',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2021-01-05',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '719',
      'idCpModulos' => '319',
      'dataAula' => '2021-01-06',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-12',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-13',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-19',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-20',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-26',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-01-27',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-02-02',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-02-03',
      'tempos' => '4',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
      'idPlan' => '720',
      'idCpModulos' => '320',
      'dataAula' => '2021-02-09',
      'tempos' => '1',
      'tempos2' => '0',
      'dataCriado' => '2020-10-27 17:52:00',
    )array (
    )

    When it reachs this line in your code

    $date = $level2['dataAula'];

    I have this error

    <b>Warning</b>:  Illegal string offset 'dataAula'

    But when i see the array, it looks right to me.....what do i missing?

     

    Thanks

     

  6. Hello

    I have an array where i want the join values (not sum) where the date are the same

    This my array(var_export)

    array (
      0 => 
      array (
        0 => 
        array (
          0 => 
          array (
            'dataAula' => '2020-09-21',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 4,
          ),
        ),
        1 => 
        array (
          1 => 
          array (
            'dataAula' => '2020-09-22',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 8,
          ),
        ),
        2 => 
        array (
          2 => 
          array (
            'dataAula' => '2020-09-28',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 12,
          ),
        ),
        3 => 
        array (
          3 => 
          array (
            'dataAula' => '2020-09-29',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 16,
          ),
        ),
        4 => 
        array (
          4 => 
          array (
            'dataAula' => '2020-10-06',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 20,
          ),
        ),
        5 => 
        array (
          5 => 
          array (
            'dataAula' => '2020-10-12',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 24,
          ),
        ),
        6 => 
        array (
          6 => 
          array (
            'dataAula' => '2020-10-13',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 28,
          ),
        ),
        7 => 
        array (
          7 => 
          array (
            'dataAula' => '2020-10-19',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 32,
          ),
        ),
        8 => 
        array (
          8 => 
          array (
            'dataAula' => '2020-10-20',
            'tempos' => 1,
            'tempos2' => 'Terça',
            'total' => 33,
          ),
        ),
      ),
      1 => 
      array (
        0 => 
        array (
          0 => 
          array (
            'dataAula' => '2020-10-20',
            'tempos' => 3,
            'tempos2' => 'Segunda',
            'total' => 3,
          ),
        ),
        1 => 
        array (
          1 => 
          array (
            'dataAula' => '2020-10-27',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 7,
          ),
        ),
        2 => 
        array (
          2 => 
          array (
            'dataAula' => '2020-11-02',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 11,
          ),
        ),
        3 => 
        array (
          3 => 
          array (
            'dataAula' => '2020-11-03',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 15,
          ),
        ),
        4 => 
        array (
          4 => 
          array (
            'dataAula' => '2020-11-09',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 19,
          ),
        ),
        5 => 
        array (
          5 => 
          array (
            'dataAula' => '2020-11-10',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 23,
          ),
        ),
        6 => 
        array (
          6 => 
          array (
            'dataAula' => '2020-11-16',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 27,
          ),
        ),
        7 => 
        array (
          7 => 
          array (
            'dataAula' => '2020-11-17',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 31,
          ),
        ),
        8 => 
        array (
          8 => 
          array (
            'dataAula' => '2020-11-23',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 35,
          ),
        ),
        9 => 
        array (
          9 => 
          array (
            'dataAula' => '2020-11-24',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 39,
          ),
        ),
        10 => 
        array (
          10 => 
          array (
            'dataAula' => '2020-11-30',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 43,
          ),
        ),
        11 => 
        array (
          11 => 
          array (
            'dataAula' => '2020-12-07',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 47,
          ),
        ),
        12 => 
        array (
          12 => 
          array (
            'dataAula' => '2020-12-14',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 51,
          ),
        ),
        13 => 
        array (
          13 => 
          array (
            'dataAula' => '2020-12-15',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 55,
          ),
        ),
        14 => 
        array (
          14 => 
          array (
            'dataAula' => '2021-01-04',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 59,
          ),
        ),
        15 => 
        array (
          15 => 
          array (
            'dataAula' => '2021-01-05',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 63,
          ),
        ),
        16 => 
        array (
          16 => 
          array (
            'dataAula' => '2021-01-11',
            'tempos' => 4,
            'tempos2' => 'Segunda',
            'total' => 67,
          ),
        ),
      ),
      2 => 
      array (
        0 => 
        array (
          0 => 
          array (
            'dataAula' => '2021-01-12',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 4,
          ),
        ),
        1 => 
        array (
          1 => 
          array (
            'dataAula' => '2021-01-18',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 8,
          ),
        ),
        2 => 
        array (
          2 => 
          array (
            'dataAula' => '2021-01-19',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 12,
          ),
        ),
        3 => 
        array (
          3 => 
          array (
            'dataAula' => '2021-01-25',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 16,
          ),
        ),
        4 => 
        array (
          4 => 
          array (
            'dataAula' => '2021-01-26',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 20,
          ),
        ),
        5 => 
        array (
          5 => 
          array (
            'dataAula' => '2021-02-01',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 24,
          ),
        ),
        6 => 
        array (
          6 => 
          array (
            'dataAula' => '2021-02-02',
            'tempos' => '4',
            'tempos2' => 'Terça',
            'total' => 28,
          ),
        ),
        7 => 
        array (
          7 => 
          array (
            'dataAula' => '2021-02-08',
            'tempos' => '4',
            'tempos2' => 'Segunda',
            'total' => 32,
          ),
        ),
        8 => 
        array (
          8 => 
          array (
            'dataAula' => '2021-02-09',
            'tempos' => 1,
            'tempos2' => 'Terça',
            'total' => 33,
          ),
        ),
      ),
    )[]

    So, for example i have repeated the date 2020-10-20, one with "tempos =1" and another with "tempos=3"

    I'm looking to have only one date with concatened tempos field

    Example

    array (
            'dataAula' => '2020-10-20',
            'tempos' => 1+3,
            'tempos2' => 'Terça',
            'total' => 33,
          ),

    So what i have now is this code but not getting what i need

     

    foreach ($finalCronograma as $sub) {
                    $row = current($sub);
                    if (isset($result[$row[0]['dataAula']])) {
                        $result[$row[0]['dataAula']]['tempos'] .= '+' . $row[0]['tempos'];
                    } else {
                        $result[$row[0]['dataAula']] = $sub;
                    }
                }

     

    any help?

  7. 37 minutes ago, Barand said:

    Any min/max limits on hours/day/hours per week?

    No, no limit

    But usually a class don't have more than 7/8 hours week in specific subject(for instance, multimedia have in one subject with 8 hours per week, 3 hours with all student class + 5 hours each group(class divided in 2)

     

    Sending my form to get full picture 

     

    Regards

    form.png

  8. Hi Barand

    Thanks for helping

    Let me explain all the process

    Here, in Portugal, we have professional school for students who don't want to go to unervisity. The student have 3 years to finish this.

    All subjects ( math , english, etc) have more than one module. I mean, Math have 10 modules, each one must have a grade to have a final  classification, Portuguese have 12 modules, English 6...and so on.

    Every teacher must do a scheduler for all modules (The teacher choose the subject, then, the year (10,11,12),. After choosing the year the system print out wich modules he must give to students. After that he chooses the starting date, the days he gonna gives classes and the hours for each day. Finally the system will generate the scheduler for all year modules. 

    What

    57 minutes ago, Barand said:

    I have been following this topic (I say "following" but that is an exaggeration) and I admit I totally clueless about

    • what the inputs to this process are
    • what the goal of the process is
    • what the rules are to achieve the goal and what the constraints are
    • what T1, T2, shift3, shift4 are

    Apart from that...

    About your questions

    1. what the inputs to this process are? Inputs are subjects, year, starting date, days, hours

    2. what the goal of the process is . The goal is create a scheduler

    3. what the rules are to achieve the goal and what the constraints are. Rules are only defined the school year calendar and holidays

    4. what T1, T2, shift3, shift4 are .

    T1 is all classes for monday, T2 is all classes for tuesday,T3 is all classes for wednesday, etc

    shift1 is for monday when the classes is divided in 2 (covid 19)

    shift2 is for tuesday

    shift3 is for wednesday

     

    So imagine this scenario

    I choose Math,year 10, the system gonna print 3 modules

    Module 1 - 34 hours

    Module 2 - 44 hours

    Module 1 - 60 hours

    The classes is divided in 2 groups, each one in diffetent day, suppose monday and wednesday

    so

    i use an array shift1 to have all classes dates for group 1 in monday

    so i use an array shift3 to have all classes dates for group 2 in wedenesday

     

    it is clear now or more information is needed?

    Sorry about my english,

     

    Thanks

     

     

  9. Hi

     

    Iv'e create 5 differents arrays for each week day.

    Usually there is only 2 students groups, but in some cases, i can have all the student class in one day or more + 2 others days for groups (class divided in 2)

     $cronograma = array();
        $shift1 = array();
        $shift2 = array();
        $shift3 = array();
        $shift4 = array();
        $shift5 = array();

    So my main array is called cronograma, and the others are (by days week, monday,etc)

    at the end i'm using array_merge jo merge non empty arrays

    In the following example i have 2 week days with all class (Monday and Tuesday), T1 and T2 in array

    And i have 2 groups shifts in another 2 days (wednesday, thursday), Shift3 and shift4

     

    This is the produced final array

     

    2020-10-19 - 1 - T1 - 1
    2020-10-20 - 2 - T2 - 3
    2020-10-26 - 1 - T1 - 4
    2020-10-27 - 2 - T2 - 6
    2020-11-02 - 1 - T1 - 7
    2020-11-03 - 2 - T2 - 9
    2020-11-09 - 1 - T1 - 10
    2020-11-10 - 2 - T2 - 12
    2020-11-16 - 1 - T1 - 13
    2020-11-17 - 2 - T2 - 15
    2020-11-23 - 1 - T1 - 16
    2020-11-24 - 2 - T2 - 18
    2020-11-30 - 1 - T1 - 19
    2020-12-07 - 1 - T1 - 20
    2020-12-14 - 1 - T1 - 21
    2020-12-15 - 2 - T2 - 23
    2021-01-04 - 1 - T1 - 24
    2021-01-05 - 2 - T2 - 26
    2021-01-11 - 1 - T1 - 27
    2021-01-12 - 2 - T2 - 29
    2021-01-18 - 1 - T1 - 30
    2021-01-19 - 2 - T2 - 32
    2021-01-25 - 1 - T1 - 33
    2021-01-26 - 2 - T2 - 35
    2021-02-01 - 1 - T1 - 36
    2021-02-02 - 2 - T2 - 38
    2021-02-08 - 1 - T1 - 39
    2021-02-09 - 2 - T2 - 41
    2021-02-22 - 1 - T1 - 42
    2021-02-23 - 2 - T2 - 44
    2021-03-01 - 1 - T1 - 45
    2021-03-02 - 2 - T2 - 47
    2021-03-08 - 1 - T1 - 48
    2021-03-09 - 2 - T2 - 50
    2021-03-15 - 1 - T1 - 51
    2021-03-16 - 2 - T2 - 53
    2021-03-22 - 1 - T1 - 54
    2021-03-23 - 2 - T2 - 56
    2021-04-05 - 1 - T1 - 57
    2021-04-06 - 2 - T2 - 59
    2021-04-12 - 1 - T1 - 60
    2021-04-13 - 2 - T2 - 62
    2021-04-19 - 1 - T1 - 63
    2021-04-20 - 2 - T2 - 65
    2021-04-26 - 1 - T1 - 66
    2021-04-27 - 2 - T2 - 68
    2021-05-03 - 1 - T1 - 69
    2021-05-04 - 2 - T2 - 71
    2021-05-10 - 1 - T1 - 72
    2021-05-11 - 2 - T2 - 74
    2021-05-17 - 1 - T1 - 75
    2021-05-18 - 2 - T2 - 77
    2021-05-24 - 1 - T1 - 78
    2021-05-25 - 2 - T2 - 80
    2021-05-31 - 1 - T1 - 81
    2021-06-01 - 2 - T2 - 83
    2021-06-07 - 1 - T1 - 84
    2021-06-08 - 2 - T2 - 86
    2021-06-14 - 1 - T1 - 87
    2021-06-15 - 2 - T2 - 89
    2021-06-21 - 1 - T1 - 90
    2021-06-22 - 2 - T2 - 92
    2021-06-28 - 1 - T1 - 93
    2021-06-29 - 2 - T2 - 95
    2021-07-05 - 1 - T1 - 96
    2021-07-06 - 2 - T2 - 98
    2021-07-12 - 1 - T1 - 99
    2021-07-13 - 1 - T2 - 100
    2020-10-21 - 5 - Shift3 - 5
    2020-10-28 - 5 - Shift3 - 10
    2020-11-04 - 5 - Shift3 - 15
    2020-11-11 - 5 - Shift3 - 20
    2020-11-18 - 5 - Shift3 - 25
    2020-11-25 - 5 - Shift3 - 30
    2020-12-02 - 5 - Shift3 - 35
    2020-12-09 - 5 - Shift3 - 40
    2020-12-16 - 5 - Shift3 - 45
    2021-01-06 - 5 - Shift3 - 50
    2021-01-13 - 5 - Shift3 - 55
    2021-01-20 - 5 - Shift3 - 60
    2021-01-27 - 5 - Shift3 - 65
    2021-02-03 - 5 - Shift3 - 70
    2021-02-10 - 5 - Shift3 - 75
    2021-02-17 - 5 - Shift3 - 80
    2021-02-24 - 5 - Shift3 - 85
    2021-03-03 - 5 - Shift3 - 90
    2021-03-10 - 5 - Shift3 - 95
    2021-03-17 - 5 - Shift3 - 100
    2021-03-24 - 5 - Shift3 - 105
    2021-04-07 - 5 - Shift3 - 110
    2021-04-14 - 5 - Shift3 - 115
    2021-04-21 - 5 - Shift3 - 120
    2021-04-28 - 5 - Shift3 - 125
    2021-05-05 - 5 - Shift3 - 130
    2021-05-12 - 5 - Shift3 - 135
    2021-05-19 - 5 - Shift3 - 140
    2021-05-26 - 5 - Shift3 - 145
    2021-06-02 - 5 - Shift3 - 150
    2021-06-09 - 5 - Shift3 - 155
    2021-06-16 - 5 - Shift3 - 160
    2021-06-23 - 5 - Shift3 - 165
    2021-06-30 - 1 - Shift3 - 166
    2020-10-22 - 5 - Shift4 - 5
    2020-10-29 - 5 - Shift4 - 10
    2020-11-05 - 5 - Shift4 - 15
    2020-11-12 - 5 - Shift4 - 20
    2020-11-19 - 5 - Shift4 - 25
    2020-11-26 - 5 - Shift4 - 30
    2020-12-03 - 5 - Shift4 - 35
    2020-12-10 - 5 - Shift4 - 40
    2020-12-17 - 5 - Shift4 - 45
    2021-01-07 - 5 - Shift4 - 50
    2021-01-14 - 5 - Shift4 - 55
    2021-01-21 - 5 - Shift4 - 60
    2021-01-28 - 5 - Shift4 - 65
    2021-02-04 - 5 - Shift4 - 70
    2021-02-11 - 5 - Shift4 - 75
    2021-02-18 - 5 - Shift4 - 80
    2021-02-25 - 5 - Shift4 - 85
    2021-03-04 - 5 - Shift4 - 90
    2021-03-11 - 5 - Shift4 - 95
    2021-03-18 - 5 - Shift4 - 100
    2021-04-08 - 5 - Shift4 - 105
    2021-04-15 - 5 - Shift4 - 110
    2021-04-22 - 5 - Shift4 - 115
    2021-04-29 - 5 - Shift4 - 120
    2021-05-06 - 5 - Shift4 - 125
    2021-05-13 - 5 - Shift4 - 130
    2021-05-20 - 5 - Shift4 - 135
    2021-05-27 - 5 - Shift4 - 140
    2021-06-03 - 5 - Shift4 - 145
    2021-06-17 - 5 - Shift4 - 150
    2021-06-24 - 5 - Shift4 - 155
    2021-07-01 - 5 - Shift4 - 160
    2021-07-08 - 5 - Shift4 - 165
    2021-07-15 - 1 - Shift4 - 166

    So T1 and T2 must have 100 hours total - done

    Shift3 and shift4 must have 166 hours total - done

     

    Now i must:

     each id(subject) apply 50 hours of t1 and t2

    each id(subject apply 80 hours of Shift3 and shift4

     

    So i need foreach to iterate between them

    first is array of subject id

    second is array subjects hours

    and third is the main array

     

    right?

     

  10. What i have so far is this

     

     $newAr = array(); //array
            $id = explode(',',$idPlan); //string to array (subjects id)
    
            foreach ($id as $idPlan) {
                foreach ($tot as $t){ //array with hours
                    $tempos = (int)$t['tempos'];
                }
                foreach($cronograma as $c){ //where i have all dates and hours per day
                    if($c[3]<= $tempos){
                        $newAr[] = $idPlan;
                        $newAr[] = $c[0];
                    }
                }
                print "<br>";
                echo "data: ".$idPlan;
                print "<br>";
                print_r($newAr);
            }

    The result is this

    
    dados: 58
    Array ( [0] => 58 [1] => 2020-09-21 [2] => 58 [3] => 2020-09-28 [4] => 58 [5] => 2020-10-12 [6] => 58 [7] => 2020-10-19 [8] => 58 [9] => 2020-10-26 [10] => 58 [11] => 2020-11-02 [12] => 58 [13] => 2020-11-09 [14] => 58 [15] => 2020-11-16 [16] => 58 [17] => 2020-11-23 [18] => 58 [19] => 2020-11-30 [20] => 58 [21] => 2020-12-07 [22] => 58 [23] => 2020-12-14 [24] => 58 [25] => 2021-01-04 [26] => 58 [27] => 2021-01-11 [28] => 58 [29] => 2021-01-18 [30] => 58 [31] => 2021-01-25 [32] => 58 [33] => 2021-02-01 ) 
    dados: 60
    Array ( [0] => 58 [1] => 2020-09-21 [2] => 58 [3] => 2020-09-28 [4] => 58 [5] => 2020-10-12 [6] => 58 [7] => 2020-10-19 [8] => 58 [9] => 2020-10-26 [10] => 58 [11] => 2020-11-02 [12] => 58 [13] => 2020-11-09 [14] => 58 [15] => 2020-11-16 [16] => 58 [17] => 2020-11-23 [18] => 58 [19] => 2020-11-30 [20] => 58 [21] => 2020-12-07 [22] => 58 [23] => 2020-12-14 [24] => 58 [25] => 2021-01-04 [26] => 58 [27] => 2021-01-11 [28] => 58 [29] => 2021-01-18 [30] => 58 [31] => 2021-01-25 [32] => 58 [33] => 2021-02-01 [34] => 60 [35] => 2020-09-21 [36] => 60 [37] => 2020-09-28 [38] => 60 [39] => 2020-10-12 [40] => 60 [41] => 2020-10-19 [42] => 60 [43] => 2020-10-26 [44] => 60 [45] => 2020-11-02 [46] => 60 [47] => 2020-11-09 [48] => 60 [49] => 2020-11-16 [50] => 60 [51] => 2020-11-23 [52] => 60 [53] => 2020-11-30 [54] => 60 [55] => 2020-12-07 [56] => 60 [57] => 2020-12-14 [58] => 60 [59] => 2021-01-04 [60] => 60 [61] => 2021-01-11 [62] => 60 [63] => 2021-01-18 [64] => 60 [65] => 2021-01-25 [66] => 60 [67] => 2021-02-01 )

    So, my code is changing id subject but is starts again in first array element

    Iv'e checked and i know why, originaly hours array have 2 elements (34,34), so with this foreach

     foreach ($tot as $t){
                    $tempos = (int)$t['tempos'];
                }

    it is starting again with 0 until reaching 34 and no 68 like i pretend in second iteration

     

    Whats wrong?

     

     

  11.  

    8 minutes ago, requinix said:

    So... I'm right, then? You need those 4 pairs of start/end dates?

    What I said before about splitting the one array into two (one for each subject), then go through each array looking for the total=0 and total=34 dates and then for the total=34+time (that allows you to support any class duration instead of total=36 which only works for 2 hour classes) and total=68 dates.

    Exactly

    I'm trying to figure out how to do it...i'm lost

    😄

  12. Yes, this chart belongs to a case with class with only 14 students and only one subject with 4 hours each time.

    For instance, the school have classes with only 14 students so no need more than one group.

    In this case or other similar there is 2 groups, and each group can have classes in different days (this case), that's why you see 2,2, 4,4, etc

    The most important is to separate subject by id getting the start date and the end date because i can store into database the start and the end of each subject

  13. I understand your questions and they are really important to avoid any problem.

    In this case the most important is last dates because is when the subjetcs end. If they are rescheduled a note must be writen by the teacher, 

    Rigth now, the most important is to separate subject by id getting the start date and the end date.

    See the image with only one subject, now they ask me to have only one example like this with more than one subject

     

    crongrama.png

  14. 21 minutes ago, requinix said:

    Where are you getting 2021-02-01 from? Where does the 34 from $tot come in?

    How about this: given those three arrays,

    
    $cronograma = array(
    	"2020-09-21" => array("2020-09-21", 2, 2, 2),
    	"2020-09-28" => array("2020-09-28", 2, 2, 4)
    );
    
    $id = array(
    	58,
    	60
    );
    
    $tot = array(
    	34,
    	34
    );

    (1) what is the output you want to get, and (2) what thought process did you follow for you to come up with that output?

    Hi

     

    Thanks for your reply

     

    To explain you i must tell you what a want to achieve

    The first array ($cronograma) has information about dates,hours and total hours(last is incermented)

    My full array have this data

    2020-09-21 - 2 - 0 - 2
    2020-09-22 - 2 - 0 - 2
    2020-09-28 - 2 - 0 - 4
    2020-09-29 - 2 - 0 - 4
    2020-10-06 - 2 - 0 - 6
    2020-10-12 - 2 - 0 - 6
    2020-10-13 - 2 - 0 - 8
    2020-10-19 - 2 - 0 - 8
    2020-10-20 - 2 - 0 - 10
    2020-10-26 - 2 - 0 - 10
    2020-10-27 - 2 - 0 - 12
    2020-11-02 - 2 - 0 - 12
    2020-11-03 - 2 - 0 - 14
    2020-11-09 - 2 - 0 - 14
    2020-11-10 - 2 - 0 - 16
    2020-11-16 - 2 - 0 - 16
    2020-11-17 - 2 - 0 - 18
    2020-11-23 - 2 - 0 - 18
    2020-11-24 - 2 - 0 - 20
    2020-11-30 - 2 - 0 - 20
    2020-12-07 - 2 - 0 - 22
    2020-12-14 - 2 - 0 - 24
    2020-12-15 - 2 - 0 - 22
    2021-01-04 - 2 - 0 - 26
    2021-01-05 - 2 - 0 - 24
    2021-01-11 - 2 - 0 - 28
    2021-01-12 - 2 - 0 - 26
    2021-01-18 - 2 - 0 - 30
    2021-01-19 - 2 - 0 - 28
    2021-01-25 - 2 - 0 - 32
    2021-01-26 - 2 - 0 - 30
    2021-02-01 - 2 - 0 - 34
    2021-02-02 - 2 - 0 - 32
    2021-02-08 - 2 - 0 - 36
    2021-02-09 - 2 - 0 - 34
    2021-02-22 - 2 - 0 - 38
    2021-02-23 - 2 - 0 - 36
    2021-03-01 - 2 - 0 - 40
    2021-03-02 - 2 - 0 - 38
    2021-03-08 - 2 - 0 - 42
    2021-03-09 - 2 - 0 - 40
    2021-03-15 - 2 - 0 - 44
    2021-03-16 - 2 - 0 - 42
    2021-03-22 - 2 - 0 - 46
    2021-03-23 - 2 - 0 - 44
    2021-04-05 - 2 - 0 - 48
    2021-04-06 - 2 - 0 - 46
    2021-04-12 - 2 - 0 - 50
    2021-04-13 - 2 - 0 - 48
    2021-04-19 - 2 - 0 - 52
    2021-04-20 - 2 - 0 - 50
    2021-04-26 - 2 - 0 - 54
    2021-04-27 - 2 - 0 - 52
    2021-05-03 - 2 - 0 - 56
    2021-05-04 - 2 - 0 - 54
    2021-05-10 - 2 - 0 - 58
    2021-05-11 - 2 - 0 - 56
    2021-05-17 - 2 - 0 - 60
    2021-05-18 - 2 - 0 - 58
    2021-05-24 - 2 - 0 - 62
    2021-05-25 - 2 - 0 - 60
    2021-05-31 - 2 - 0 - 64
    2021-06-01 - 2 - 0 - 62
    2021-06-07 - 2 - 0 - 66
    2021-06-08 - 2 - 0 - 64
    2021-06-14 - 2 - 0 - 68
    2021-06-15 - 2 - 0 - 66
    2021-06-22 - 2 - 0 - 68

     The second array " ids" is 2 differents school subjects (ex: Mat and English)

     

    The third array is related to hours of each school subjects (ex: Mat and English), in this case 34 hours each 

     

    So my main array start with date (when it starts until when its end (68 hours)

     

    What i want is to slit this info

    So, since i have 2 ids (58, 60)

    id        stardate          endDate            total 

    58     2020-09-21     2021-02-01        34

    60    2021-02-08      2021-06-22        68

     

    So i can insert into database those values

    So i started to put foreach for array ids, inside foreach for array cronograma, and inside hours array

     

    But the response given is not what i'm looking for

  15. Let me explain my problem. I have an array with dates and numbers in format ($cronograma)

    Ex:

    Array ( [2020-09-21] => Array ( [0] => 2020-09-21 [1] => 2 [2] => 2 [3] => 2 ) [2020-09-28] => Array ( [0] => 2020-09-28 [1] => 2 [2] => 2 [3] => 4 )

    Then i have another array with 2 ids (in this case 58,60) ($id)

    Finally i have a third array with numbers only (in this case 34,34) $tot

    So what i want is cross information beween them, for example for id 58 I must get dates (first element and last element when $tot = 34) for id 60 I must get dates (first element after $tot =34 and last element of array)

    Whath i have so far is this

    foreach ($id as $idPlan) { foreach ($cronograma as $c) { $t1 = 0; foreach ($tot as $d) { $t1 += (int)$d['tempos']; if ($c[3] == $t1) { $newAr[] =$idPlan; $newAr[] = $c[0]; } } } }

    My response

    array(8) { [0]=> string(2) "58" [1]=> string(10) "2021-02-01" [2]=> string(2) "58" [3]=> string(10) "2021-06-14" [4]=> string(2) "60" [5]=> string(10) "2021-02-01" [6]=> string(2) "60" [7]=> string(10) "2021-06-14" } null

    So it's clear that i have all repeated

    I should have a line like:

    58 - 2020-09-21 -2021-02-01

    Any help?

  16. Hi

    26 minutes ago, gw1500se said:

    Add this before the 'foreach' to make sure it does what you expect.

    
    echo "<pre>";
    print_r(range( 0, $datediff ));
    echo "</pre>";

    The errors are likely related. Which lines are 661 and 670?

    It does do..

    The problem is inside the foreach loop, i have put some echos and this is really strange, if you look my code you willsee a lot of echos to help me to debug

     if($haveDesdobramento === "1") {
                if ((isSegunda( $internal_date )) && !isExcludedDate( $internal_date )) {
                    $cronograma[$this_month][] = $this_day;
                    if($temposSegunda != null) {
                        if ($haveDesdobramento === "1" && $haveAllClass === null) {
                            if($totais<=$horasTurnos){
                                $t = $sum + $temposSegunda;
                                if($t > $horasTurnos){
                                    $n1 = abs($t - $horasTurnos);
                                    $temposSegunda = $temposSegunda - $n1;
                                }
                                if ($sameDayShifts === "1") {
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = $temposSegunda;
                                }
                                else{
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = 0;
                                    $total += $temposSegunda;
                                    $cronograma[$this_month][] = $total;
                                }
                            }
    
                        }
                        if ($haveDesdobramento === "1" && $haveAllClass === "1") {
                            echo "1ª Soma:".$sum;
                            print "<br>";
                            if($sum<$horasAll){
                                echo "2ª Soma:".$sum;
                                print "<br>";
                                if(($sum+ $temposSegunda) > $horasAll){
                                    echo "3ª Soma:".($sum+ $temposSegunda);
                                    print "<br>";
                                    $n1 = abs(($sum+ $temposSegunda) - $horasAll);
                                    $temposSegunda = $temposSegunda - $n1;
                                    print "<br>";
                                }
                                if ($sameDayShifts === "1") {
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = $temposSegunda;
                                }
                                else {
                                    echo "aqui 2";
                                    print "<br>";
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = 0;
                                    $total += $temposSegunda;
                                    $cronograma[$this_month][] = $total;
                                    $sum += $temposSegunda;
    
                                }
                            }
                        }
                        else{
                            echo "aqui";
                            $days = floor($horas/$temposSegunda);
                            $hours_remaining = $horas - $days * $temposSegunda;
                            $cronograma[$this_month][] = $hours_remaining;
                        }
                    }
                }
            }

    And with all those debugs i'm receiving this

    1ª Soma:0
    2ª Soma:0
    aqui 2
    1ª Soma:3
    2ª Soma:3
    aqui 2
    1ª Soma:6
    2ª Soma:6
    aqui 2
    1ª Soma:9
    2ª Soma:9
    aqui 2
    1ª Soma:12
    2ª Soma:12
    aqui 2
    1ª Soma:15
    2ª Soma:15
    aqui 2
    1ª Soma:18
    2ª Soma:18
    aqui 2
    1ª Soma:21
    2ª Soma:21
    aqui 2
    1ª Soma:24
    2ª Soma:24
    aqui 2
    1ª Soma:27
    2ª Soma:27
    aqui 2
    1ª Soma:30
    2ª Soma:30
    aqui 2
    1ª Soma:33
    2ª Soma:33
    aqui 2
    1ª Soma:36
    2ª Soma:36
    aqui 2
    1ª Soma:39
    2ª Soma:39
    aqui 2
    1ª Soma:42
    2ª Soma:42
    aqui 2
    1ª Soma:45
    2ª Soma:45
    aqui 2
    1ª Soma:48
    2ª Soma:48
    aqui 2
    1ª Soma:51
    2ª Soma:51
    aqui 2
    1ª Soma:54
    2ª Soma:54
    aqui 2
    1ª Soma:57
    2ª Soma:57
    aqui 2
    1ª Soma:60
    2ª Soma:60
    aqui 2
    1ª Soma:63
    2ª Soma:63
    aqui 2
    1ª Soma:66
    2ª Soma:66
    aqui 2
    1ª Soma:69
    2ª Soma:69
    aqui 2
    1ª Soma:72
    2ª Soma:72
    aqui 2
    1ª Soma:75
    2ª Soma:75
    aqui 2
    1ª Soma:78
    2ª Soma:78
    aqui 2
    1ª Soma:81
    2ª Soma:81
    aqui 2
    1ª Soma:84
    2ª Soma:84
    aqui 2
    1ª Soma:87
    2ª Soma:87
    aqui 2
    1ª Soma:90
    2ª Soma:90
    aqui 2
    1ª Soma:93
    2ª Soma:93
    aqui 2
    1ª Soma:96
    2ª Soma:96
    aqui 2
    1ª Soma:99
    2ª Soma:99
    3ª Soma:102
    
    aqui 2
    1ª Soma:100
    1ª Soma:100

    And the array is created i have this (last 3 lines)

    2021-06-07 - 3 - 0 - 99
    2021-06-14 - 1 - 0 - 100
    2021-06-21 - 1 - 0 - 100

    same in 2 differents dates but i have reached the 100 (hours) in first date (2021-06-14)

    I don't understand why this last line

    Thanks

  17. Hello

    I'm having problems regarding coding  right the following problem

    One class (students) can have class all together or/and divided (haveDesdobramento) into 2 shifts

    So in the beginning i'm choosing all class and defined 100 hours

    Using a foreach because i need to check  holidays, school breaks, start and end of school

     foreach (range( 0, $datediff ) as $day) {
            $internal_date = date( INTERNAL_FORMAT, strtotime( "{$startDate} + {$day} days" ) );
            $this_day = date( INTERNAL_FORMAT, strtotime( $internal_date ) );
            $this_month = date( INTERNAL_FORMAT, strtotime( $internal_date ) );
            if($haveDesdobramento === "1") {
                if ((isSegunda( $internal_date )) && !isExcludedDate( $internal_date )) {
                    $cronograma[$this_month][] = $this_day;
                    if($temposSegunda != null) {
                        if($sum>=$horasAll){
                            $nhoras = $sum - $horasAll;
                            $temposSegunda = $temposSegunda - $nhoras;
                            echo "tSegunda: ".$temposSegunda;
                        }
                        if ($haveDesdobramento === "1" && $haveAllClass === null) {
                            if($totais<=$horasTurnos){
                                if ($sameDayShifts === "1") {
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = $temposSegunda;
                                }
                                else{
                                    $days = floor($horas/$temposSegunda);
                                    $hours_remaining = $horas - $days * $temposSegunda;
                                    $cronograma[$this_month][] = $hours_remaining;
                                }
                            }
    
                        }
                        if ($haveDesdobramento === "1" && $haveAllClass === "1") {
                            if($sum<=$horasAll){
                                if ($sameDayShifts === "1") {
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = $temposSegunda;
                                }
                                else {
                                    $cronograma[$this_month][] = $temposSegunda;
                                    $cronograma[$this_month][] = 0;
                                    $total += $temposSegunda;
                                    $cronograma[$this_month][] = $total;
    
                                }
                            }
                        }
                        else{
                            $days = floor($horas/$temposSegunda);
                            $hours_remaining = $horas - $days * $temposSegunda;
                            $cronograma[$this_month][] = $hours_remaining;
                        }
                    }
                    $sum += $temposSegunda;
                }
            }

     

    It works but it stops at 102, not 100 like it should (choosing 3 hours each time) and the array returned gives me this

     

     

    Any help?

     

    Thanks

     

    2021-06-07 - 3 - 0 - 99
    2021-06-14 - 3 - 0 - 102
    Notice: Undefined offset: 1 in /home/esmaior/public_html/miga/db/crud/profissionais/response.php on line 661
    
    2021-06-21 - - 0 - 102
    Notice: Undefined offset: 1 in /home/esmaior/public_html/miga/db/crud/profissionais/response.php on line 670
    
    Notice: Undefined offset: 1 in /home/esmaior/public_html/miga/db/crud/profissionais/response.php on line 661
    
    2021-06-28 - - 0 - 102
    Notice: Undefined offset: 1 in /home/esmaior/public_html/miga/db/crud/profissionais/response.php on line 670
    
    Total: 102

     

     

     

  18. Hello

    Can somepne help me with this issue

    I have a query who is returning some records

    ID        disciplina                                moduloUfcd             idcpDisciplinas                         anoTurma 

    58,      Comunicação Visual,                 8599,                                   49,                                           11
    59,      Comunicação Visual,                 133,                                     49,                                           11

    60,      Comunicação Visual,                 134,                                     49,                                           10

    When i trying to put this into an array with just one line (merge all with number 49 (idcpDisciplinas) and (anoTurma) 11) i can't get the desired output

     

    My sql query is this one

    select c.idPlan, cD.disciplina, cM.moduloUfcd, p.Nome, t.Turma, a.Ano, c2.curso,
                                   c.validCron, c.cronograma, c.dataLimite, c.idProfessor,cM.horas,cM.tempos,
                                   c.pdfCronograma, c2.curso, cM.discModulo, cM.idcpDisciplinas, cM.ano as anoTurma 
                                    from cpDiscProfessores c
                                             inner join cpDisciplinas cD on c.idcpDisciplinas = cD.idCpDisciplinas
                                             inner join cpModulos cM on c.idCpModulos = cM.idCpModulos
                                             inner join professores p on c.idProfessor = p.idProfessor
                                             left join turmas t on c.idTurma = t.idTurma
                                             inner join anosescolares a on c.idAnoEscolar = a.idAnoEscolar
                                             left join cursos c2 on c.idCursos = c2.idCursos
                                    where a.Estado = 1;

     

    And in php what i have is this

     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
            $final = array();
            $json = array();
            foreach ($result as $row) {
                $moduloUfcd= $row['moduloUfcd'];
                if (!isset($moduloUfcd[$moduloUfcd])) {
                    $horas= $row['horas'];
                    $final[$moduloUfcd]['idPlan'] = $row['idPlan'];
                    $final[$moduloUfcd]['disciplina'] = $row['disciplina'];
                    $final[$moduloUfcd]['Nome'] = $row['Nome'];
                    $final[$moduloUfcd]['Turma'] = $row['Turma'];
                    $final[$moduloUfcd]['anoTurma'] = $row['anoTurma'];
                    $final[$moduloUfcd]['curso'] = $row['curso'];
                    $final[$moduloUfcd]['validCron'] = $row['validCron'];
                    $final[$moduloUfcd]['cronograma'] = $row['cronograma'];
                    $final[$moduloUfcd]['dataLimite'] = $row['dataLimite'];
                    $final[$moduloUfcd]['idProfessor'] = $row['idProfessor'];
                    $final[$moduloUfcd]['pdfCronograma'] = $row['pdfCronograma'];
                    $final[$moduloUfcd]['discModulo'] = $row['discModulo'];
                    $final[$moduloUfcd]['idcpDisciplinas'] = $row['idcpDisciplinas'];
                    $final[$moduloUfcd]['moduloUfcd'] = array();
    
                }
                $final[$moduloUfcd]['moduloUfcd'][] = $row['moduloUfcd'];
                $final[$moduloUfcd]['horas'][] = $row['horas'];
                $final[$moduloUfcd]['tempos'][] = $row['tempos'];
    
    
            }
            foreach ($final as $moduloUfcd => $cron) {
    
                $json[] = $cron;
            }
    
            echo json_encode($json);

    What it gives is :

    [
    {
    idPlan: "60",
    disciplina: "Comunicação Visual",
    Nome: "XXXXXXXXX",
    Turma: "11ºO",
    anoTurma: "11",
    curso: "Técnico de Audiovisuais",
    validCron: "-1",
    cronograma: "0",
    dataLimite: "2020-10-30",
    idProfessor: "168",
    pdfCronograma: "/XXXXX/pdf/profissionais/cronogramas/Cronograma -Técnico de Audiovisuais-8599.pdf",
    discModulo: "8599",
    idcpDisciplinas: "49",
    moduloUfcd: [
    "8599"
    ],
    horas: [
    "25"
    ],
    tempos: [
    " 34 "
    ]
    }
    ]

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.