How to show the results of a query in mysql with php in an html table?

0

What I need is that when executing a query to the database, this result is displayed in a table and in each column what corresponds, is done with php and mysql what happened to them what I was doing

   $query = 'SELECT DISTINCT per.PERSC_Nombre as nombre , per.PERSC_ApellidoPaterno as apellido_paterno ,per.PERSC_ApellidoMaterno as apellido_materno
FROM cji_paciente pa
JOIN cji_persona per ON per.PERSP_Codigo = pa.PERSP_Codigo
JOIN cji_consulta con ON con.PACI_Codigo = pa.PACI_Codigo
JOIN cji_diagnostico dg ON dg.CONS_Codigo = con.CONS_Codigo
JOIN cji_diagnostico_fase dgf ON dgf.DIAG_Codigo = dg.DIAG_Codigo
JOIN cji_emprestablecimiento eme ON eme.EESTABP_Codigo = con.COMPP_Codigo
WHERE eme.EESTABP_Codigo =  "11"
AND dgf.FASDIA_TipoDias =  "2"/* FASDIA_TipoDias=0 lunes a sabado(fase 1) FASDIA_TipoDias=1 lun-mir-vier FASDIA_TipoDias=2 mar-jue-sa FASDIA_TipoDias=3 lu a sabado */
AND dgf.FASDIA_FlagFase =  "1"
AND con.PROD_Codigo =  "30852"
AND NOT 
EXISTS (
SELECT * 
FROM cji_consulta
WHERE PACI_Codigo = pa.PACI_Codigo
AND CONS_FechaRegistro = CURDATE( )
)';
$result = mysql_query($query) or die('Consulta fallida: ' . mysql_error());
$rows   = mysql_fetch_row($result);

?>

<table border="1">
        <thead>
            <tr>
                <th>Nombre</th>
                <th>Apellido Paterno</th>
                <th>Aperllido Materno</th>
            </tr>
        </thead>
        <tbody>
        <?php
            foreach ($rows as $row) {
        ?>
            <tr>
                <td><?php echo $row[0]; ?></td>
                <td><?php echo $row[1]; ?></td>
                <td><?php echo $row[2]; ?></td>
            </tr>
        <?php 
        }
         ?>
        </tbody>
    </table>
    
asked by ingswsm 17.04.2017 в 21:56
source

2 answers

1

Since you are inside the same page you can do the following place a while inside the table so that it fills up I leave the example is only part of the html not the php code:

<table border="1">
        <thead>
            <tr>
                <th>Nombre</th>
                <th>Apellido Paterno</th>
                <th>Aperllido Materno</th>
            </tr>
        </thead>
        <tbody>
        <?php
            while($row = mysql_fetch_row($result)) {
        ?>
            <tr>
                <td><?php echo $row['nombre']; ?></td>
                <td><?php echo $row['apellido_paterno']; ?></td>
                <td><?php echo $row['apellido_materno']; ?></td>
            </tr>
        <?php 
        }
         ?>
        </tbody>
    </table>
  

Note: On your label you place codeigniter, if it is for the framework. The code would be different.

    
answered by 17.04.2017 в 23:47
0

but I'm wrong I think what you use is fine. But you must pass that html string containing your table with your data to a method in JS and this will show you your table inside a div or whatever.

Mostrar(){
  $.ajax({
                data:  parametros,
                url:   'realizasConsulta.php',
                type:  'post',
                beforeSend: function () {
                        $("#resultado").html("Procesando, espere por favor...");
                },
                success:  function (response) {
                        $("#resultado").html(response);
                }
        });
} 

You must use JQuery to make it work. I hope you serve

result is the element where you are going to show your table, either a div or whatever

    
answered by 18.04.2017 в 03:03