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

Asked

Viewed 48 times

0

I’m trying to create a code covers send messages between users of a system in php, the problem and I can send the message from one user to another but wish it was possible to send to all users, or else to more than one , the same message without having to rewrite.

I created a checkbox field but I’m not able to treat this field, with php

I’m using codeigniter, from what I understand it will give me post a Boolean, true or false

seems easy, just check with if and false or true and register.

but then as I create a loop, to go through the users, I’m a little lost in this question, someone can give me a help 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 IS THE CODE THAT TRIES TO CREATE THE LOOP AND SEND IT 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 and true or false to call this function.

1 answer

1

Looking fast:

First I saw a little mistake in the "foreach" you Zera the $i every time he starts, then he gets $i=0 in everything. has q by before the foreach.

Second does not have the sending codes, but how it works with 1 TEM q work with the loop. In the sending code, has to put at least one !$_POST['envia_todos'] (If it is just a checkbox field with the name sent).

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.
}
  • Yes truth had not seen that I was restarting the $i to 0 inside the loop that trip, and the post I’m doing in another part of the code that I didn’t post, but for now it’s not working yet, but I’m stirring, if anyone finds any more problem!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.