Problem with php code to send simultaneous messages to the database!

0

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.

    
asked by anonymous 22.02.2017 / 15:35

1 answer

1

Looking fast:

First I saw a little foreach in the foreach, it will $i every time it starts, so it gets $i=0 at all. have q before foreach.

Second does not have the send codes, but how does it work with 1 TEM that works with the loop. In the code you send, you must have at least a !$_POST['envia_todos'] (If it is just a checkbox field with the name send_todos).

if(!$_POST['envia_todos']){
// Código que consulta no banco e cria um loop com o resultado
// dentro do loop o código de envio com o paramentro de cada usuário 
// (nome, cidade, o que tiver no banco que faça parte da mensagem) que veio da consulta.
}
    
22.02.2017 / 16:00