I need help with a sql that I'm doing in php

0

to show me the students who are enrolled in each course, by means of a table called registers, which contains the course id and also the user id, but I do not know if I have to call the data by variables of session? they help me

<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<?php
 include("conexion.php");
$IDC = $_SESSION['ID_CURSO'];
 $usuario = $_SESSION['ID_USUARIO'];
 
 $SQL = "SELECT * FROM registros where ID_CURSO= $IDC  AND ID_USUARIO= $usuario";

$result= $conn->query($SQL);

if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
$usuario = $row['ID_USUARIO'];
$IDC = $row['ID_CURSO'];
$NOMBREU = $row['NOMBRE_USUARIO'];



       echo"
      <tr>
			   <td>".$usuario."</td>
			   <td>".$IDC."</td>
			   <td>".$NOMBREU."</td>

            <td>
        <div class='table-data-feature'>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Ver'>
                <i class='zmdi zmdi-mail-send'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Editar'>
                <i class='zmdi zmdi-edit'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Eliminar'>
                <i class='zmdi zmdi-delete'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Más'>
                <i class='zmdi zmdi-more'></i>
            </button>
        </div>
    </td>
			</tr>
			"; 
   }     
}else
{
  
}
?>
 
    
asked by Julio Adalberto Reyes Argueta 08.08.2018 в 16:35
source

1 answer

1

if this code comes from another page or a form your code is fine, you're just missing the session, look:

<?php
session_start();
 include("conexion.php");
$IDC = $_SESSION['ID_CURSO'];
 $usuario = $_SESSION['ID_USUARIO'];

 $SQL = "SELECT * FROM registros where ID_CURSO= $IDC  AND ID_USUARIO= $usuario";

$result= $conn->query($SQL);

if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
$usuario = $row['ID_USUARIO'];
$IDC = $row['ID_CURSO'];
$NOMBREU = $row['NOMBRE_USUARIO'];



       echo"
      <tr>
               <td>".$usuario."</td>
               <td>".$IDC."</td>
               <td>".$NOMBREU."</td>

            <td>
        <div class='table-data-feature'>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Ver'>
                <i class='zmdi zmdi-mail-send'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Editar'>
                <i class='zmdi zmdi-edit'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Eliminar'>
                <i class='zmdi zmdi-delete'></i>
            </button>
            <button class='item' data-toggle='tooltip' data-placement='top' title='Más'>
                <i class='zmdi zmdi-more'></i>
            </button>
        </div>
    </td>
            </tr>
            "; 
   }     
}else
{
  echo"sentencia no valida";
}
?>

otherwise, there must be an error in your sql statement

    
answered by 08.08.2018 в 16:47