<?php
	// include Database connection file 
	include("db_connection.php");

	// Design initial table header 
	$clinica=$_GET['clinica'];
	$doc=$_GET['doc'];
	
	echo "<h3>Pacientes ".$doc."</h3><p>";
	$data = '<table class="table table-bordered table-striped" id="myTable">
						<tr>
							<th>Apellido</th>
							<th>Nombre</th>
							<th>DNI</th>
							<th>Email</th>
							<th>Profesional</th>
							<th>Entrar</th>
							<th>Turno</th>
						</tr>';

	$query = "SELECT * FROM tabla1 WHERE clinica LIKE '$clinica' AND usuario LIKE '$doc' order by paciente ASC";

	if (!$result = mysqli_query($con, $query)) {
        exit(mysqli_error($con));
    }

    // if query results contains rows then featch those rows 
    if(mysqli_num_rows($result) > 0)
    {
    	$number = 1;
    	while($row = mysqli_fetch_assoc($result))
    	{
    		$data .= '<tr>
				<td><p onclick="GetUserDetails('.$row['id_pac'].')">'.$row['paciente'].'</p></td>
				<td><p onclick="GetUserDetails('.$row['id_pac'].')">'.$row['nombre'].'</p></td>
				<td><p onclick="GetUserDetails('.$row['id_pac'].')">'.$row['dni'].'</p></td>
				<td><p onclick="GetUserDetails('.$row['id_pac'].')">'.$row['email'].'</p></td>
				<td><p onclick="GetUserDetails('.$row['id_pac'].')">'.$row['usuario'].'</p></td>
				<td>
					<a class="btn btn-warning" href="./pac.php?cual=1&id_pac='.$row['id_pac'].'" role="button">Entrar</a>
				</td>
				<td>
					<button onclick="DeleteUser('.$row['id_pac'].')" class="btn btn-danger">Turno</button>
				</td>
    		</tr>';
    		$number++;
    	}
    }
    else
    {
    	// records now found 
    	$data .= '<tr><td colspan="6">No hay pacientes!</td></tr>';
    }

    $data .= '</table>';

    echo $data;
?>


