Table does not display name relative to Foreign Key PHP Table

0

I need to query the table and return the Date in the first column, Name (FK) in the second column, and other FK-dependent data in their respective columns . I've tried the various forms of INNER JOIN and I can not show the patient's name, just his code. Would anyone give me a hint, or what do I have to change in the code?

My tables are:

Table ........ || Countryside Agenda ..... || Date, Time, Patient_Code, Missed
Patients ... || Code, Name, Phone, Cod_Convenio, phone, cell phone

Connected by

calendar: ....... Cod_Paciente
Patients: ... Code

I can already mount the table with all the schedules but I can not display the patient name within the relative column. I've tried the while in several ways.

Here is the code:

include("conexao.php");  

// Escolhendo apenas a data atual.  
$query = "select * from agenda WHERE Data BETWEEN ('$date') AND ('$date');";  
$resultado = mysql_query($query,$conexao) or die(mysql_error());  

//Fazendo o join na tabela pacientes  
$query2 = "SELECT
            p.codigo,
            nome,
            sexo,
            profissao,
            celular,
            observacoes,
            codigo_convenio,
            a.codigo_paciente, 
            hora, 
            faltou 
           FROM pacientes p 
           JOIN agenda a ON a.codigo_paciente = p.codigo 
           ORDER BY data,hora";

$resultado2=mysql_query($query2,$conexao) or die(mysql_error());  

// montar a tabela   

if(mysql_num_rows($resultado)>0)  
    print "<table border='3' ALIGN='center'><FONT FACE='Arial' SIZE='10' COLOR='black'>";  

print "<tr colspan='10' rowspan='10'><td id='celula0'>Hora</td><td id='celula1'>Paciente</td><td id='celula2'>Presente?</td><td id='celula3'>P.Saude</td><td id='celula4'>Tel</td><td id='celula2'>Histórico</td></tr>";  

while ($info2=mysql_fetch_array($resultado2))
{  
    while ($info = mysql_fetch_array($resultado))  
    {  
        print "<tr colspan='10' rowspan='10'><td id='celula0'>$info[hora]</td> <td id='celula1'>$info2[nome]</td><td id='celula2'>$info[faltou]</td><td id='celula3'>$info[codigo_paciente]</td><td id='celula4'>$info[codigo_paciente]</td><td id='celula4'>$info[codigo_paciente]</td></tr>";  
    }  
    print "</table>";  
}  
?>  
</body>  
</html>  

    
asked by anonymous 27.04.2017 / 02:26

0 answers