PHP - Consultas Msql con campos ID

 
Vista:
sin imagen de perfil

Consultas Msql con campos ID

Publicado por Miguel Perez (1 intervención) el 30/08/2014 00:07:31
Hola a todos y todas.
Estoy haciendo una consulta a una tabla donde hay un campo Id.
Todo bien, pero en la respuesta correspondiente al Id me responde con un numero (que es el que corresponde a la respuesta de texto en la tabla que enlaza el ID).
Cuál sería el script correcto para que en vez del número aparezca el nombre correspondiente al examen?
Este es el script que tengo y cuando lo ejecuto me dice :Indefined index: result2 in C:....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
    include ("conexion.php");
 
?>
 
<html>
    <meta http-equiv="Content-type" content="text/html; charset=utf8" />
    <head>
    <title>Alumnos</title>
        </head>
    <body>
    <center>
    <br>
 
    <?php
    mysql_query("set names 'iso-8859-1'");
 
    $documento=$_POST['nombre'];
    $tabla="pag_alumn";
 
$sql = "SELECT   nombre,identificacion, apellidos,telefono,Idexam_alumn,profesor,factura,hor_por_pagar,saldo_por_pagar,fe_saldo FROM $tabla where nombre='$documento' AND (saldo_por_pagar NOT IN (0))  ORDER BY fe_saldo";
 
 
$result = mysql_query($sql);
 
    $result = mysql_query("SELECT  nombre,identificacion,  apellidos, telefono,Idexam_alumn ,profesor,factura,hor_por_pagar,saldo_por_pagar,fe_saldo FROM $tabla where nombre='$documento' AND (saldo_por_pagar NOT IN (0)) ORDER BY fe_saldo");
 
 
 
$exam = 'Idexam_alumn';
 
$result2 = mysql_query("SELECT examen, from exámenes where Idexam_alumn='$exam'");
 
     if ($row = mysql_fetch_array($result))
{
    echo "<table border = '1'><caption align='top'><font color=red><big><big><strong>SALDOS ALUMNOS</strong></font></big></caption> \n";
    echo "<tr></td><th><strong><font color = blue>Nombre</font></strong></td><th><strong><font color =blue>Apellidos</FONT></strong></td><th><strong><font color = blue>Identificacion</font></strong></td><th><strong><font color = blue>Tel&eacute;fono</font></strong></td><th><strong><font color = blue>Examen</font></strong></td><th><strong><font color = blue>Profesor</font></strong></td><th><strong><font color = blue>Factura</font></strong></td><th><strong><font color =darkness red>Horas por pagar</font></strong></td><th><strong><font color =darkness red>Saldo por Pagar</font></strong></td><th><strong><font color = darkness red>Fecha Saldo</font></strong></td></th></tr> \n";
    do {
    echo "<tr><td>".$row["nombre"]."</td><td>".$row["apellidos"]."</td><td>".$row["identificacion"]."</td><td>".$row["telefono"]."</td><td>".$row["result2"]."</td><td>".$row["profesor"]."</td><td>".$row["factura"]."</td><td>".$row["hor_por_pagar"]."</td><td>".$row["saldo_por_pagar"]."</td><td>".$row["fe_saldo"]."</td></tr> \n";
    } while ($row = mysql_fetch_array($result));
 
 
    echo "</table>";
    } else {
    echo "! No se ha encontrado ningun registro !";
    }
    ?>
 
 
    </center>
    </body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Salvador

Consultas Msql con campos ID

Publicado por Salvador (125 intervenciones) el 30/08/2014 04:59:56
Creo que tienes una coma de mas despues de examen, quitasela a ver si funciona, tambien utiliza nombres de campos y tablas sin acentos ni caracteres especiales.

SELECT examen, from exámenes where Idexam_alumn='$exam'");
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar