Foros del Web » Programando para Internet » PHP »

Generar pdf haciendo una consulta a mysql utilizando dompdf

Estas en el tema de Generar pdf haciendo una consulta a mysql utilizando dompdf en el foro de PHP en Foros del Web. Hola que tal, miren lo que quiero hacer es que desde una pagina llamada perfiles.php el usuario realize una busqueda escribiendo el nombre de la ...
  #1 (permalink)  
Antiguo 15/08/2012, 15:37
 
Fecha de Ingreso: mayo-2012
Ubicación: Distrito Federal
Mensajes: 49
Antigüedad: 11 años, 11 meses
Puntos: 9
Pregunta Generar pdf haciendo una consulta a mysql utilizando dompdf

Hola que tal, miren lo que quiero hacer es que desde una pagina llamada perfiles.php el usuario realize una busqueda escribiendo el nombre de la persona y esta muestre los resultados desde una base de datos; una vez mostrados tendra la posibilidad de generar un archivo pdf con dichos resultados.

Para hacer la conversion a pdf utilizo la libreria dompdf, utilizando 2 archivos: el primero es el que contiene el boton de busqueda perfiles.php y el segundo archivo es el que realiza el trabajo de conversion llamado pdf_send.php.

Todo funciona bien, ya que al realizar la busqueda y dar click en el boton de generar pdf, este ultimo se genera correctamente con los datos obtenidos en la busqueda.

Mi problema es que los resultados obtenidos en la busqueda los tengo que mostrar en campos de texto para poder procesarlos y mandarlos a llamar por medio de la funcion POST y asi se cree el pdf y NO QUIERO ESO.

Quisiera poder mostrar los resultados sin utilizar campos de texto, es decir, hacerlo directamente con los valores generados por el juego de registros, pero no se como mandarlos a llamar y procesarlos en el archivo pdf_send.php

Aqui pongo el codigo de los 2 archivos que utilizo para ver si me pueden decir como resolver esta problematica, de antemano gracias por la ayuda.

perfiles.php

Código:
<?php require_once('Connections/bd_futbol.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_datos = "-1";
if (isset($_POST['busqueda'])) {
  $colname_datos = $_POST['busqueda'];
}
mysql_select_db($database_bd_futbol, $bd_futbol);
$query_datos = sprintf("SELECT * FROM datos_jugador WHERE nombre LIKE %s", GetSQLValueString("%" . $colname_datos . "%", "text"));
$datos = mysql_query($query_datos, $bd_futbol) or die(mysql_error());
$row_datos = mysql_fetch_assoc($datos);
$totalRows_datos = mysql_num_rows($datos);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Perfiles</title>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:896px;
	height:178px;
	z-index:1;
	left: 106px;
	top: 85px;
}
#apDiv2 {
	position:absolute;
	width:468px;
	height:37px;
	z-index:2;
	left: 371px;
	top: 20px;
}
-->
</style>
</head>

<body>
<div id="apDiv1">
  <form action="pdf_send.php" method="post" enctype="multipart/form-data" name="formtabla" target="_blank" id="formtabla">
    <table width="878" border="1">
      <tr>
        <td width="185">NOMBRE:</td>
        <td width="677"><label>
          <input name="nombre" type="text" id="nombre" value="<?php echo $row_datos['nombre']; ?>" />
       &nbsp;
       <input name="ap_pat" type="text" id="ap_pat" value="<?php echo $row_datos['ap_pat']; ?>" />
       &nbsp; 
       <input name="ap_mat" type="text" id="ap_mat" value="<?php echo $row_datos['ap_mat']; ?>" />
        </label></td>
      </tr>
      <tr>
        <td>APODO</td>
<td><label>
  <input name="apodo" type="text" id="apodo" value="<?php echo $row_datos['apodo']; ?>" />
  &nbsp;NUMERO 
  <input name="numero" type="text" id="numero" value="<?php echo $row_datos['numero']; ?>" />
  &nbsp;POSICION 
  <input name="posicion" type="text" id="posicion" value="<?php echo $row_datos['posicion']; ?>" />
  <br />
  ALTURA: 
  <?php echo $row_datos['altura']; ?><br />
</label></td>
      </tr>
      <tr>
        <td><img src="imagenes/imagenes_jugadores/<?php echo $row_datos['imagen']; ?>" width="119" height="119" /><br />
        <br /></td>
        <td><label>
          <input type="submit" name="enviar" id="enviar" value="Generar PDF" />
        </label></td>
      </tr>
    </table>
  </form>
</div>
<div id="apDiv2">
  <form action="perfiles.php" method="post" enctype="multipart/form-data" name="formBUSQUEDA" id="formBUSQUEDA">
    ESCRIBA EL NOMBRE: 
    <label>
      <input type="text" name="busqueda" id="busqueda" />
    </label>
 &nbsp;
 <label>
   <input type="submit" name="buscar" id="buscar" value="Buscar" />
 </label>
  </form>
</div>
</body>
</html>
<?php
mysql_free_result($datos);
?>

pdf_send.php

Código:
    <?php 

    require_once("dompdf/dompdf_config.inc.php");

    $conexion = mysql_connect("localhost", "root", "");

    mysql_select_db("sistema", $conexion);
	

$html ='

<html>
<head>
<title>Envio de Sugerencias</title>
<style type="text/css">
<!--
#datos {
	position:absolute;
	width:780px;
	left: 164px;
	top: 316px;
	text-align: center;
}
#apDiv1 #form1 table tr td {
	text-align: center;
	font-weight: bold;
}
#apDiv2 {
	position:absolute;
	width:49px;
	height:45px;
	z-index:2;
	left: 12px;
	top: 11px;
}
#apDiv1 #notificacion table tr td {
	text-align: center;
}
#apDiv1 #notificacion table tr td {
	text-align: left;
}
#apDiv1 #notificacion table tr td {
	text-align: center;
	font-family: Arial, Helvetica, sans-serif;
}
#apDiv3 {
	position:absolute;
	width:814px;
	height:115px;
	z-index:1;
	left: 34px;
	text-align: center;
	top: 11px;
}
-->
</style>
</head>

<body>
<div id="apDiv3">
  <table width="81%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
    <tr>
      <td><table width="100%" border="0">
        <tr>
          <td style="text-align: center"><img src="imagenes/anonymous.jpg" alt="" width="387" height="225"></td>
        </tr>
        <tr>
          <td><p>&nbsp;</p>
            <p style="font-family: Helvetica LT Condensed; color: #008895; font-weight: bold; font-size: 22px; text-align: center;">Ficha Tecnica</p></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td style="font-family: Helvetica LT Condensed; font-size: 18px;"><spanHelvetica LT Condensed"; font-size: 18px;">
            <span style="font-weight: bold">Nombre:</span>&nbsp;'.$_POST["nombre"].' '.$_POST["ap_pat"].' '.$_POST["ap_mat"].'</td>
        </tr>
        <tr>
          <td style="font-family: Helvetica LT Condensed; font-size: 18px;"><span style="font-weight: bold">Apodo:</span>&nbsp;'.$_POST["apodo"].'</td>
        </tr>
        <tr>
          <td style="font-family: Helvetica LT Condensed; font-size: 18px;"><span style="font-weight: bold">Numero:</span>&nbsp;'.$_POST["numero"].'</td>
        </tr>
        <tr>
          <td><p>&nbsp;</p>
            <p><span style="font-family: Helvetica LT Condensed; font-size: 18px;"><span style="font-weight: bold">Posicion:</span>&nbsp;'.$_POST["posicion"].'</span></p>
            <p>&nbsp;</p>
            <p>&nbsp;</p></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
    </tr>
  </table>
</div>
</body>
</html>

'; 

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("Ficha_Tecnica.pdf", array('Attachment'=>'0'));
    ?>

Última edición por chuntaro18; 16/08/2012 a las 01:57

Etiquetas: dompdf, haciendo, html, mysql, pdf, sql, tabla, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:47.