Comunidad de diseño web y desarrollo en internet online

Funcion

Citar            
MensajeEscrito el 02 Feb 2007 11:40 pm
Hola amigos, como puedo hacer una funcion de que me pueda recolectar una columna de una tabla, ya haciendo esta funcion puedo mandar a imprimir a PDF una tabla:

Código :

<?php
define('FPDF_FONTPATH','font/');
require('mc_table.php');
include ("conf.inc.php");
$query = "SELECT  nombre,apellidoFROM alumnos ORDER BY nombre ASC"; 
$resultado = mysql_query ($query) or die (mysql_error());
$filasDevueltas = mysql_num_rows($resultado);

//Las filasDevueltas hacen el numero de celdas que imprimirá el PDF

if ($filasDevueltas > 0){
   while (list($nombre_selec,$apellido_selec) = mysql_fetch_array($resultado)){
   //
   Aqui vendria la Funcion nombre ();
        Aqui vendria la funcion Apellido();
   //   
   $pdf=new PDF_MC_Table('l');
      $pdf->Open();
      $pdf->AddPage();
      $pdf->SetFont('Arial','',14);
      $pdf->SetLeftMargin(15);
      $pdf->SetRightMargin(15);
      $pdf->SetTopMargin(15);
      $pdf->Cell(125);
      $pdf->Cell(25,10,'NOMBRES',2,0,'C');
      $pdf->Ln(30);
      
      $pdf->SetWidths(array(50,215));
      for($i=0;$i<$filasDevueltas;$i++)
         //$pdf->Row(array(funcion_nombre(),$funcion_apellido));
      $pdf->Output();
      }
   } else {
      echo "no se obtuvo nada";
}
mysql_close ($cnx);
?>


Trate de hacer esto:

Código :

if ($filasDevueltas > 0){
   while (list($nombre_selec,$descripcion_selec) = mysql_fetch_array($resultado)){
   $pdf=new PDF_MC_Table('l');
   $pdf->Open();
        ........

Y lo que me hace es imprimir el registro nombre y el registro apellido y repetirmelo en el numero de celdas de la variable $filasDevueltas.

Si alguien me ayuda,le agradeceria mucho.

Saludos.

Por atomoclip

61 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 03 Feb 2007 12:30 am
lee las normas del foro (sobre todo en la sección títulos) y utiliza un poco la cabeza, no todos tenemos en nuestro servidor el archivo mc_table.php

Por fael

BOFH

2443 de clabLevel

3 tutoriales
2 articulos

 

firefox
Citar            
MensajeEscrito el 03 Feb 2007 12:32 am
Disculpa Fael, ahi va mc_table.php

Código :

<?php
require('fpdf.php');

class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;

function SetWidths($w)
{
   //Set the array of column widths
   $this->widths=$w;
}

function SetAligns($a)
{
   //Set the array of column alignments
   $this->aligns=$a;
}

function Row($data)
{
   //Calculate the height of the row
   $nb=0;
   for($i=0;$i<count($data);$i++)
      $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
   $h=5*$nb;
   //Issue a page break first if needed
   $this->CheckPageBreak($h);
   //Draw the cells of the row
   for($i=0;$i<count($data);$i++)
   {
      $w=$this->widths[$i];
      $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
      //Save the current position
      $x=$this->GetX();
      $y=$this->GetY();
      //Draw the border
      $this->Rect($x,$y,$w,$h);
      //Print the text
      $this->MultiCell($w,5,$data[$i],0,$a);
      //Put the position to the right of the cell
      $this->SetXY($x+$w,$y);
   }
   //Go to the next line
   $this->Ln($h);
}

function CheckPageBreak($h)
{
   //If the height h would cause an overflow, add a new page immediately
   if($this->GetY()+$h>$this->PageBreakTrigger)
      $this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
   //Computes the number of lines a MultiCell of width w will take
   $cw=&$this->CurrentFont['cw'];
   if($w==0)
      $w=$this->w-$this->rMargin-$this->x;
   $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
   $s=str_replace("\r",'',$txt);
   $nb=strlen($s);
   if($nb>0 and $s[$nb-1]=="\n")
      $nb--;
   $sep=-1;
   $i=0;
   $j=0;
   $l=0;
   $nl=1;
   while($i<$nb)
   {
      $c=$s[$i];
      if($c=="\n")
      {
         $i++;
         $sep=-1;
         $j=$i;
         $l=0;
         $nl++;
         continue;
      }
      if($c==' ')
         $sep=$i;
      $l+=$cw[$c];
      if($l>$wmax)
      {
         if($sep==-1)
         {
            if($i==$j)
               $i++;
         }
         else
            $i=$sep+1;
         $sep=-1;
         $j=$i;
         $l=0;
         $nl++;
      }
      else
         $i++;
   }
   return $nl;
}
}
?>

Por atomoclip

61 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.