Use result of an array in another php query

0

Hello I'm hardly new to PHP and Mysql I want to make a query with the result of another query arrar

<?php
session_start();
if (isset($_SESSION[' u_usuario'])){
    $usuario1 = $_SESSION[' u_usuario'];
}
else{
    header("Location: index.php");
} 
include("conexion.php");
$refcuatri = " II2018 "; //Cambiar cuatrimestre para prevenir errores
//busqueda por del alumno por cuatrimester y matricula
$query3= mysqli_query($conexion,"SELECT refgrupo, refcarrera FROM inscripcion WHERE refcuatri='$refcuatri' AND matricula ='$usuario1'");
$q3 = mysqli_fetch_array($query3); 
$refgrupo=$q3['refgrupo']; // es igual a 4-A 
$refcarrera=$q3['refcarrera']; //es igual a SI
//busqueda del profesr por referencia del grupo y referencia de la carre que anteriormente se habia creado las variables
//A PARTIR DE AQUI NO ME LEE LAS VARIABLES PARA HACER OTRA CONSULTA
$query4= mysqli_query($conexion,"SELECT refprofesor FROM asigna_materia WHERE refgrupo='$refgrupo' AND refcarrera='$refcarrera'");
$q4 = mysqli_fetch_array($query4);
$refprofesor=$q4['refprofesor']; //NO DA VALOR

echo $refgrupo; // ES IGUAL A 4-A
echo $refcarrera; // ES IGUAL A SI
echo $refprofesor; // NO DA VALOR
?>

And that is the result but from the query4 does not take the variables the information that has inside it to do another search someone could help me: c

the fields are correct!

    
asked by gmp_97 30.07.2018 в 22:58
source

1 answer

0

Put your query query3 to a while to cicle the result, another thing, whenever you concatenate variables, cut the chain, sometimes it does not work directly, in the validation of the variable of sesión u_usuario , it would be useful plus a empty()

<?php
session_start();
if (!empty($_SESSION[' u_usuario'])){
    $usuario1 = $_SESSION[' u_usuario'];
}

else{
    header("Location: index.php");
} 

include("conexion.php");
$refcuatri = " II2018 "; //Cambiar cuatrimestre para prevenir errores
//busqueda por del alumno por cuatrimester y matricula
$query3= mysqli_query($conexion,"SELECT refgrupo, refcarrera FROM inscripcion WHERE refcuatri='". $refcuatri. "' AND matricula ='".$usuario1."'");
while( $q3 = mysqli_fetch_array($query3) ){
  $refgrupo=$q3['refgrupo']; // es igual a 4-A 
  $refcarrera=$q3['refcarrera']; //es igual a SI
  //busqueda del profesr por referencia del grupo y referencia de la carre que anteriormente se habia creado las variables
  //A PARTIR DE AQUI NO ME LEE LAS VARIABLES PARA HACER OTRA CONSULTA
  $query4= mysqli_query($conexion,"SELECT refprofesor FROM asigna_materia WHERE refgrupo='".$refgrupo."' AND refcarrera='".$refcarrera."'");
  $q4 = mysqli_fetch_array($query4);
  $refprofesor=$q4['refprofesor']; //NO DA VALOR

  echo $refgrupo; // ES IGUAL A 4-A
  echo $refcarrera; // ES IGUAL A SI
  echo $refprofesor; // NO DA VALOR
} 

?>
    
answered by 30.07.2018 в 23:16