Query to display data from a single user of MySQL tables

1

I need to show on my page the contents of a table according to the user who has logged in. I am including the connection and the consultations where I must access to show me the user's data, which are already loaded in the fields of the tables in the database.

Am I doing the queries and tables well to be displayed on my page?

<?php
session_start();
include "../conexion.php";
include "conexion.php";
$re=mysql_query("SELECT * FROM user_alumno 
                WHERE CURP='".$_POST['Usuario']."' 
                AND CONTRASENA='".$_POST['Password']."'") or die(mysql_error());
if(isset($arreglo)){
  $_SESSION['Usuario']=$arreglo;
  header("Location: ../admin.php");
}else{
  header("Location: ../login.php?error=datos no validos");
}

$re=mysql_query("SELECT * FROM basico 
                  WHERE CURP ='".$_POST['NOMBRE']."' 
                  AND APELLIDO_PATERNO='".$_POST['APELLIDO_MATERNO']."' ")  
$re2=mysql_query("SELECT * FROM basico WHERE CURP ");
$basico=0;
echo '<table border="0px" width="100%">';
while ($f=mysql_fetch_array($re)) {
  if($basico  !=$f['basico']){
      echo '<tr><td>CURP: '.$f['basico'].' </td></tr>';
  }
  $basico=$f['basico'];
  echo '<tr>
          <td>'.$f['CURP'].'</td>
          <td>'.$f['NOMBRE'].'</td>
          <td>'.$f['APELLIDO_PATERNO'].'</td>
          <td>'.$f['APELLIDO_MATERNO'].'</td>
        </tr>';
}
echo '</table>';

$re=mysql_query("SELECT * FROM boleta WHERE CURP='".$_POST['Usuario']."'");
if(isset($arreglo)){
  $_SESSION['Usuario']=$arreglo;
  header("Location: ../admin.php");
}else{
  header("Location: ../login.php?error=datos no validos");
}

$re=mysql_query("SELECT * FROM boleta WHERE CURP'".$_POST['CURP']."' 
    AND   CALIFICACION1='".$_POST['CALIFICACION1']."' 
    AND CALIICACION2='".$_POST['CALIFICACION2']."' 
    AND CALIICACION3='".$_POST['CALIFICACION3']."' 
    AND CALIFICACION_FINAL='".$_POST['CALIFICACIONF']."' 
    AND ASISENCIA1='".$_POST['ASISTENCIA1']."' 
    AND CALIICACION2='".$_POST['CALIFICACION2']."' 
    AND ASISTENCIA3='".$_POST['ASISTENCIA3']."'");
//Falta la condicion del campo de BB.DD CURL
$re2=mysql_query("SELECT * FROM basico WHERE CURP=... ");
$boleta=0;
echo '<table border="0px" width="100%">';
while ($f=mysql_fetch_array($re)) {
        if($basico  !=$f['basico']){
          echo '<tr><td>CURP: '.$f['basico'].' </td></tr>';
        }
        $basico=$f['basico'];
        echo '<tr>
                <td>'.$f['CURP'].'</td>
                <td>'.$f['CALIFICACION1'].'</td>
                <td>'.$f['CALIFICACION2'].'</td>
                <td>'.$f['CALIFICACION3'].'</td>
                <td>'.$f['CALIFICACIONF'].'</td>
                <td>'.$f['ASISTENCIA1'].'</td>
                <td>'.$f['ASISTENCIA2'].'</td>
                <td>'.$f['ASISTENCIA3'].'</td>
              </tr>';
}
echo '</table>';
    
asked by abdiel sandoval 10.06.2017 в 08:03
source

2 answers

1

I pass a quick review of your code, I have corrected only the most obvious failures. But to give you an example, when you make the queries to the BB.DD always assign them to the same variable.

<?php
session_start();
include "../conexion.php";
include "conexion.php";
$re=mysql_query("SELECT * FROM user_alumno 
                WHERE CURP='".$_POST['Usuario']."' 
                AND CONTRASENA='".$_POST['Password']."'") or die(mysql_error());
if(isset($arreglo)){
$_SESSION['Usuario']=$arreglo;
  header("Location: ../admin.php");

}else{
    //DISTINTO NUMERO DE <td> LA TABLA SALDRA MAL FORMADA
  header("Locatio colspan="3"n: ../login.php?error=datos no validos");
}

$re=mysql_query("SELECT * FROM basico 
                  WHERE CURP ='".$_POST['NOMBRE']."' 
                  AND APELLIDO_PATERNO='".$_POST['APELLIDO_MATERNO']."' ");

$re2=mysql_query("SELECT * FROM basico WHERE CURP ");
$basico=0;
echo '<table border="0px" width="100%">';
while ($f=mysql_fetch_array($re)) {
  if($basico  !=$f['basico']){
      //DISTINTO NUMERO DE <td> LA TABLA SALDRA MAL FORMADA
      echo '<tr><td colspan="3">CURP: '.$f['basico'].' </td></tr>';
  }
  $basico=$f['basico'];
  echo '<tr>
          <td>'.$f['CURP'].'</td>
          <td>'.$f['NOMBRE'].'</td>
          <td>'.$f['APELLIDO_PATERNO'].'</td>
          <td>'.$f['APELLIDO_MATERNO'].'</td>
        </tr>';
echo '</table>';

$re=mysql_query("SELECT * FROM boleta WHERE CURP='".$_POST['Usuario']."'");
if(isset($arreglo)){
  $_SESSION['Usuario']=$arreglo;
  header("Location: ../admin.php");
}else{
  header("Location: ../login.php?error=datos no validos");
}

$re=mysql_query("SELECT * FROM boleta WHERE CURP'".$_POST['CURP']."' 
    AND   CALIFICACION1='".$_POST['CALIFICACION1']."' 
    AND CALIICACION2='".$_POST['CALIFICACION2']."' 
    AND CALIICACION3='".$_POST['CALIFICACION3']."' 
    AND CALIFICACION_FINAL='".$_POST['CALIFICACIONF']."' 
    AND ASISENCIA1='".$_POST['ASISTENCIA1']."' 
    AND CALIICACION2='".$_POST['CALIFICACION2']."' 
    AND ASISTENCIA3='".$_POST['ASISTENCIA3']."')";

$re2=mysql_query("SELECT * FROM basico WHERE CURP ");
$boleta=0;
echo '<table border="0px" width="100%">';
while ($f=mysql_fetch_array($re)) {
    if($basico  !=$f['basico']){
      echo '<tr><td>CURP: '.$f['basico'].' </td></tr>';
    }
    $basico=$f['basico'];
    echo '<tr>
            <td>'.$f['CURP'].'</td>
            <td>'.$f['CALIFICACION1'].'</td>
            <td>'.$f['CALIFICACION2'].'</td>
            <td>'.$f['CALIFICACION3'].'</td>
            <td>'.$f['CALIFICACIONF'].'</td>
            <td>'.$f['ASISTENCIA1'].'</td>
            <td>'.$f['ASISTENCIA2'].'</td>
            <td>'.$f['ASISTENCIA3'].'</td>
          </tr>';
}
echo '</table>';
    
answered by 10.06.2017 в 18:02
0

You should put a WHERE id_usuario = id_usuario in the query (first user_id is from the "ticket" table and the second user_id would be from the user table.

    
answered by 10.06.2017 в 09:39