Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/11/2012, 13:58
Avatar de gokufast
gokufast
 
Fecha de Ingreso: abril-2007
Mensajes: 540
Antigüedad: 17 años
Puntos: 3
Respuesta: como mostrar un popup que muestre un resultado de una consulta a una BD

bueno menos mal que pude encontrar la respuesta, lo adapte un poco a mis necesidades pero aca pongo la respuesta para el que pueda llegar a necesitarla.

index.php
Código PHP:
<div class="wrapper">
    <h1>Headline</h1>
    <p>texto.</p>
    <?php
    $link 
mysql_connect("localhost","root","") or die ("Error: No se ha podido establecer la conexión con el servidor" mysql_error());
    
mysql_select_db("xxx_yyy_zzz",$link) or die ("Error: Base de Datos no encontrada" mysql_error());
    
    
mysql_query("SET NAMES utf8");
    
    
$sql_1 "SELECT * FROM traspasos WHERE da = '34'";
    
$result_1=mysql_query($sql_1,$link);
    
    echo 
"<table style='border: 1px solid #ccc;' cellspacing='0' width='700' border='1'>";
        echo 
"<thead>";
                echo 
"<tr>";
                        echo 
"<th><B>Nro</B></th>";
                echo 
"</tr>";
        echo 
"</thead>";
        echo 
"<tbody>";
        while(
$row_1 mysql_fetch_array($result_1)) 
        { 
            if(isset(
$row_1['glosa']))
            {
                echo 
"<tr>";
                  echo 
"<td><a href='#".$row_1['id']."'>".$row_1['nro']."</a></td>";
                echo 
"</tr>";
            }
            else
            {
                echo 
"<tr>";
                  echo 
"<td>".$row_1['nro']."</td>";
                echo 
"</tr>";
            }
        }
        echo 
"</tbody>";
        echo 
"</table>";
    
?>
</div>
<script src="jquery-1.7.2.js"></script>
<script src="ajax-script.js"></script>
cuando hacen clic en el enlace sale el popup pero el popup extrae la informacion del archivo content.php
content.php
Código PHP:
<?php
    
    
if (isset($_POST['id'])) 
    {
        
$id $_POST['id'];
    }
    
    
    
$link mysql_connect("localhost","root","") or die ("Error: No se ha podido establecer la conexión con el servidor" mysql_error());
    
mysql_select_db("xxx_yyy_zzz",$link) or die ("Error: Base de Datos no encontrada" mysql_error());
    
    
mysql_query("SET NAMES utf8");
    
    
$sql_1 "SELECT glosa FROM traspasos WHERE id=$id";
    
$result_1=mysql_query($sql_1,$link);
    
    
$row_1 mysql_fetch_array($result_1);
    if(isset(
$row_1[0]))
    {
        echo 
"<h3>".$row_1[0]."</h3>";
        echo 
"<p>Here is some text</p>";
        echo 
"<p>Id: ".$id."</p>";
    }
    else
    {
        echo 
"<p>Esta Fila no tiene <h3>GLOSA</h3> intente con otra fila </p>";
    }

?>
hay 3 archivos mas que hacen funcionar esto son el jquery-1.7.2.js, ajax-script.js y styles.css

el jquery-1.7.2.js lo pueden descargar de la pagina jquery

ajax-script.js
Código Javascript:
Ver original
  1. (function() {
  2.  
  3.     var body = $('body');
  4.     var content = $('<div class="content"></div>');
  5.     var cover = $('<div class="cover"></div>');
  6.     var close = $('<a class="close" href="#">x</a>');
  7.     var links = $('a');
  8.     var win = {
  9.         w: $(window).width(),
  10.         h: $(window).height()
  11.     };
  12.  
  13.     links.on('click', function(e) {
  14.         e.preventDefault();
  15.         var hash = this.hash.replace('#','');
  16.         var dataString = 'id=' + hash;
  17.         body.append(cover);
  18.         $.ajax({
  19.             type: 'POST',
  20.             url: 'content.php',
  21.             data: dataString,
  22.             success: function(html) {
  23.                 body.append(content);
  24.                 content.html('');
  25.                 content.append(close);
  26.                 content.append(html);
  27.                 content.css({
  28.                     'left': (win.w / 2) - (content.width() / 2),
  29.                     'top': (win.h / 2) - (content.height() / 2)
  30.                 });
  31.                 close.on('click', function(e) {
  32.                     e.preventDefault();
  33.                     cover.remove();
  34.                     content.remove();
  35.                 });
  36.             }
  37.         });
  38.  
  39.         cover.on('click', function() {
  40.             cover.remove();
  41.             content.remove();
  42.         });
  43.     });
  44. })();

styles.css
Código CSS:
Ver original
  1. body {
  2.     margin: 0;
  3.     padding: 0;
  4.     font-family: sans-serif;
  5. }
  6. .wrapper {
  7.     width: 800px;
  8.     margin: 30px auto 0;
  9. }
  10. ul {
  11.     margin: 0;
  12.     padding: 0;
  13.     list-style: none;
  14. }
  15. li {
  16.     float: left;
  17.     width: 100px;
  18. }
  19. .cover {
  20.     width: 100%;
  21.     height: 100%;
  22.     position: fixed;
  23.     top: 0;
  24.     left: 0;
  25.     background: rgba(0, 0, 0, 0.4);
  26.     z-index: 5;
  27. }
  28. .content {
  29.     width: 400px;
  30.     padding: 0 10px;
  31.     background: #fff;
  32.     border: 5px solid #000;
  33.     border-radius: 10px;
  34.     position: fixed;
  35.     z-index: 10;
  36. }
  37. .close {
  38.     position: absolute;
  39.     top: 5px;
  40.     right: 10px;
  41.     color: #000;
  42.     text-decoration: none;
  43.     font-weight: bold;
  44. }
  45. .close:hover {
  46.     text-decoration: underline;
  47. }

ojala les sirva.