I am trying to create a code to send messages between the users of a system in php, the problem and that I can send the message from one user to another but I would like it to be possible to send to all users, one, the same message without having to rewrite.
I created a checkbox field but I can not handle this field with php
I am using codeigniter, so I understand it will give me post a boolean, true or false
seems easy, just check with if if and false or true and register.
But then how do I create a loop, to walk users, I'm kind of lost in this question, can anyone give me a hand there?
THIS IS THE CHECKBOX
<?php
echo form_label("Enviar a todos os usuarios", "newsletter");
$data = array(
'name' => 'envia_todos',
'id' => 'envia_todos',
'value' => 'accept',
'checked' => FALSE,
'style' => 'margin:10px',
);
echo form_checkbox($data);
?>
HERE THE CODE THAT TRIES TO CREATE THE LOOP AND SEND TO THE BANK
$this->load->model("Buscas_model");
$retorno =array(
"usuarios" => $this->Buscas_model->enconta_todos_usuarios(),
);
foreach($retorno['usuarios'] as $usuario){
$i = 0;
$mensagem['destinatario_id'][$i] = $usuario;
$id_mensagem = $this->Cadastros_model->mensagem($mensagem);
$i++;
}
Before arriving at this function, the code checks whether boolean is true or false to call this function.