Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/05/2016, 13:41
MrEnfurecido
 
Fecha de Ingreso: abril-2016
Mensajes: 15
Antigüedad: 8 años
Puntos: 0
Respuesta: Enviar a multiples usuarios a la vez

Cita:
Iniciado por rodocoyote15 Ver Mensaje
En el while, haces una única consulta para traerte todos los registros, y en base a ello mandarles la información.

En el for, lo que haces es una consulta para devolverte la cantidad de filas, y luego una consulta por cada usuario.

Las dos son correctas en teoría, pero dime tú, ¿cuál crees que sea la más óptima?
Saludos :D
Entiendo que con el while es mas limpio si...entonces lo pruebo asi:

Código PHP:
Ver original
  1. //Geting email and message from the request
  2.  
  3. $msg = $_POST['message'];
  4.  
  5. //Getting the firebase id of the person selected to send notification
  6. $sql = "SELECT * FROM register";
  7.  
  8. $query = mysqli_query($con,$sql);
  9.  
  10. while($res = mysqli_fetch_array($query)) {
  11.  
  12. $uniqueid = $res['firebaseid'];
  13.  
  14. //creating a firebase variable
  15. $firebase = new \Firebase\FirebaseLib(DEFAULT_URL,'');
  16.  
  17. //changing the msg of the selected person on firebase with the message we want to send
  18. $firebase->set($uniqueid.'/msg', $msg);
  19.  
  20. }

Aunque no se si me falta algún paréntesis o corchete jaja, mañana pruebo bien...

Por si acaso, probare esto también....

Código PHP:
Ver original
  1. //Geting email and message from the request
  2.  
  3. $msg = $_POST['message'];
  4.  
  5. $result = mysql_query("SELECT COUNT(*) FROM register;");
  6.  
  7. $contador1 = 1;
  8. $contador2 = 1;
  9.  
  10. for ($x = 0; $x <= '$result'; $x++) {
  11.  
  12. $sql = "SELECT * FROM register LIMIT 0,1;"
  13.  
  14. //Getting the result from database
  15. $res = mysqli_fetch_array(mysqli_query($con,$sql));
  16.  
  17. //getting the unique id from the result
  18. $uniqueid = $res['firebaseid'];
  19.  
  20. //creating a firebase variable
  21. $firebase = new \Firebase\FirebaseLib(DEFAULT_URL,'');
  22.  
  23. //changing the msg of the selected person on firebase with the message we want to send
  24. $firebase->set($uniqueid.'/msg', $msg);
  25.  
  26. $contador1= $contador+1;
  27. $contador2 = $contador+1;  
  28.  
  29. }