Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/07/2017, 06:57
Avatar de petit89
petit89
 
Fecha de Ingreso: marzo-2011
Mensajes: 1.135
Antigüedad: 13 años, 1 mes
Puntos: 170
Respuesta: Obtener variables desde consulta BD

es algun ejercicio donde obligatoriamente necesitas 2 consultas? o todo puede estar en 1 sola?

Código PHP:
Ver original
  1. // Consulta 1
  2.  
  3. $consulta = "SELECT student_id, name FROM student WHERE parent_id = $parent_id";
  4. if ($resultado = mysqli_query($enlace, $consulta)) {
  5.     while ($fila = mysqli_fetch_array($resultado)) {
  6.         $id = $fila['student_id'];
  7. $nombre = $fila['name'];
  8.     }
  9.  
  10. //AHORA PUEDES OCUPAR LAS VARIABLES PARA IMPRIMIRLAS DONDE QUIERAS O ASIGNARLAS A OTRAS VARIABLES
  11.  
  12. echo $nombre." ";
  13. echo $id;
  14.  
  15. $otra_variable = $nombre;
  16. echo $otra_variable;


saludos!
__________________
█ WebHosting / Reseller a bajo costo | Uptime Garantizado | Soporte en Español e Ingles
¿Te sirvió la respuesta? Deja un +1 (Triangulo negro al lado derecho)