2
I’m trying to record in my BD
communication data of a person and I am not able to solve, the data of this communication are Email
, Telefone Empresa
, Celular Empresa
and Ramal
, each of these are Types registered in a call table cadTipoComunicacao
and later I try to record this data in a table calls cadCommunicacao.
I have the information available:
// TIPOS DE COMUNICAÇÃO $IdTipoRamal = 1; $IdTipoTe = 3; $IdTipoCe = 4; $IdTipoEmail = 6; // INFORMAÇÃO $Ramal = 1820; $TelEmpresa = '(44) 3733-8810'; $CelEmpresa = '(44) 99898-8585'; $Email = '[email protected]';
And following structure for the agrupar
the information:
$Registros = array ( array($IdTipoRamal,$Ramal), array($IdTipoTe, $TelEmpresa), array($IdTipoCe, $CelEmpresa), array($IdTipoEmail, $Email) );
What am I doing to display the information:
for ($row = 0; $row < 4; $row++) {
echo "<ul>";
for ($col = 0; $col < 2; $col++) {
echo "<li>".$Registros[$row][$col]."</li>";
}
echo "</ul>";
}
The output of that code is this:
The insert code of the attempt I made is this:
// DADOS DA COMUNICAÇÃO
$Registros = array (
array($IdTipoRamal,$Ramal),
array($IdTipoTe, $TelEmpresa),
array($IdTipoCe, $CelEmpresa),
array($IdTipoEmail, $Email)
);
// INSERIR
for ($row = 0; $row < 4; $row++) {
// echo "<ul>";
for ($col = 0; $col < 2; $col++) {
// echo "<li>".$Registros[$row][$col]."</li>";
$crud = $pdo->prepare("INSERT INTO cadComunicacao ( IdPessoa, IdTipo, Informacao ) VALUES (?, ?, ?)");
$crud->bindParam(1, $IdPessoa , PDO::PARAM_INT);
$crud->bindParam(2, $IdTipo , PDO::PARAM_INT);
$crud->bindParam(3, $Informacao , PDO::PARAM_STR);
$retorno = $crud->execute();
}
// echo "</ul>";
}
What I am not able to do is go through the loop and record Idtipo and Informacao, and in the image the Idtipo is the first value and the Information is the second.
I can’t record everything in the field Informacao
, I need to go through the loop and record the IdPessoa
, IdTipo
and the `Information, which in the above case may be several lines for Idtype and Information.
The table where I am trying to record the information has this structure:
You want to enter the data in 2 tables right? But since in 1 table the data will be divided into several fields and in the other all the data will be inserted in a single field? If so, you can join it all in a string and insert it into the 2 table.
– Leonardo
Hello @Leonardo, I need to insert only in the table.
– adventistapr
This field of yours "Information" is a varchar of 80. Enlarge it and concatenate your fields and insert in it. Example: $information = "$variable1 . $variable2 . $variable3 . $variable4";
– Leonardo
Hello @Everson, yes, it has to be.
– adventistapr