Jump to content

gmc1103

Members
  • Posts

    251
  • Joined

  • Last visited

gmc1103's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

2

Community Answers

  1. Yes, it seems to be the code since when i use WorkBench i'm able to correct the field to participação I'm going to double check with debug where is the problem Thanks all
  2. 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&ccedil;&atilde;" 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(); } }
  3. 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 So any help what can it be??
  4. 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| +--------+-------+-----------+------------+-------------------------------------------------------------------------+----------+---------+----------+-----------+-----------+------------------------------------+-------------------+-------------------+----------------------------+---------------+----------+-----------+-----------+------------+--------------+------------+----------------------------------+------------------------+
  5. 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?
  6. 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
  7. 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?
  8. 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
  9. 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 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
  10. 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?
  11. Hello Ok iv'e changed my code and now i have arrays for each group. Now i must check wich array are not empty and compare with hours arrays, right? Regards
  12. Ok I will change the main code and let u know tomorrow...now here is 1 AM. Thanks mate, see u tomorrow.
  13. 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?
  14. Exactly I'm trying to figure out how to do it...i'm lost 😄
  15. 2 groups, 2 subjects So i must have 4 in my array
×
×
  • 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.