QUERY does not run correctly in PHP

1

I have two queries in php , after using echo $id_inspirador the value of the first query is printed correctly, but I have an error regarding the second Notice: Undefined index: id_proyecto , I do not know if the value of $id_inspirador is lost when executing the second query.

  $query = $con -> query ("SELECT id_inspirador FROM inspirador WHERE id_user = ".$id_user);
    while ($fila = mysqli_fetch_assoc($query)) {
      $id_inspirador = $fila['id_inspirador'];

  }

  $busqueda = $con -> query ("SELECT MAX(id_proyecto) FROM proyectos WHERE id_inspirador = ".$id_inspirador);
    while ($fila_busqueda = mysqli_fetch_assoc($busqueda)) {
      $id_proyecto = $fila_busqueda['id_proyecto'];       
  }
    
asked by IndiraRivas 28.11.2018 в 19:54
source

1 answer

1

Your problem in the second query is that the column you are looking for does not exist. I recommend you use an alias like this:

$busqueda = $con -> query ("SELECT MAX(id_proyecto) AS max_id FROM proyectos WHERE id_inspirador = ".$id_inspirador);
while ($fila_busqueda = mysqli_fetch_assoc($busqueda)) {
  $id_proyecto = $fila_busqueda['max_id'];       
}
    
answered by 28.11.2018 / 19:56
source