How can I show the results of an sql query inside a modal?

-1

I explain: I have a modal that opens by means of a tag, at the time of clicking, it does not show the results of the sql statement.

I make the connection to the database in the head. I save a data from a previous query to be able to make another query with that data. At the moment of showing the results, the modal opens to me empty. I would greatly appreciate your help.

//se genera un botón por cada registro
<td><a whatever='@fat' data-toggle='modal' class='btn btn-success' data-target='#visual$row[IDresguardo]'><i class='fa fa-eye'></i> Ver Registros</a></td></tr>

// modal
<div class="modal fade" id="visual<?php echo $row['IDresguardo'];?>" tabindex="-1" role="dialog" aria-hidden="true">
     <div class="modal-dialog" role="document">
     <div class="modal-content">
     <div style="background-color: #4E9C3D;" class="modal-header bg-primary">
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
           <h4 class="modal-title " id="myModalLabel"> <label>mostrar registros de BD</label></h4>
     </div>
     <div class="modal-body">

                                                        
                                                    
           <?php  
        $fecha1=$row[fecha];                                                 
        $mostrarc=mysql_query("select r.fecha, r.tipo, hi.cantidad ,h.descripcionB from herramienta h, historial hi, resguardo r where  hi.NoHerramienta=h.NoHerramienta and hi.RPEtrab='.$rpe.' and r.fecha='.$fecha1.'");


          echo "<table>";
          echo "<tr>";
          echo "<th>fech</th>";
          echo "<th>tipo</th>";
          echo "<th>Cantidad</th>";
          echo "<th>descripcionB</th>";
          echo "</tr>";

          while ($row = mysql_fetch_row($mostrarc)) {
          echo "<tr>";
          echo "<td>".$row[0]."</td>";
          echo "<td>".$row[1]."</td>";
          echo "<td>".$row[2]."</td>";
          echo "<td>".$row[3]."</td>";
          echo "</tr>";
          }
          echo "</table>";
                                                       

         ?>

                                                    
         </div>
         </div>
         </div>
                                        
         </div>
    
asked by Fernando Martínez Reséndiz 22.01.2018 в 20:56
source

2 answers

0

If the modal turns you empty, try another way. Add:

<?php
    include "archivo.php";
    error_reporting(E_ALL); //Verificar si hay errores
?>

Between the opening and closing labels of the Modal.  And in that file put the code of the query or what you want to show in the modal.

Verify that the code within the modal, works without the modal, able to have some error in what is the first query or in the second. I see that you use mysql , it is recommended to use mysqli docs

I use it that way. (With Bootstrap Modal)

    
answered by 23.01.2018 / 16:40
source
0

The code is quite messy and you do not really know what you're doing but translating this disaster a little, apparently you're doing this:

<?php

echo "tabindex="-1" role="dialog" aria-hidden="true"> × mostrar registros de BD " 
. ""
. "fech"
. "tipo"
. "Cantidad"
. "descripcionB"
. "";

while ($row = mysql_fetch_row($mostrarc)) {
   echo "" 
   . "".$row[0]
   . ""
   . "" 
   . $row[1] 
   . "" 
   . "" 
   . $row[2] 
   . "" 
   . "" 
   . $row[3] 
   . "" 
   . ""; 

} 
echo ""; 
?>

And that translates to this:

<?php

echo "tabindex="-1" role="dialog" aria-hidden="true"> × mostrar registros de BD fechtipoCantidaddescripcionB";

while ($row = mysql_fetch_row($mostrarc)) {
   echo $row[0] . $row[1] . $row[2] . $row[3]; 
} 
?>

In the first line you have errors with the delimiters of the string, you should use the following:

echo 'tabindex="-1" role="dialog" aria-hidden="true"> × mostrar registros de BD "fech" "tipo" "Cantidad" "descripcionB"';

Taking into account these errors it is most likely that $mostrarc have similar errors, check your query. I also appreciate that you are using the mysql_ functions and these are discontinued, use mysqli_ instead. Check the documentation .

FORMAT YOUR CODE ALWAYS , it will be easier to understand and find mistakes in that way.

Finally, within your loop while you can throw the whole result of your query to make sure you are getting results:

while ($row = mysql_fetch_row($mostrarc)) {
  echo var_export($row, true);
}
    
answered by 22.01.2018 в 21:44