Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/09/2014, 19:42
juansemaster
 
Fecha de Ingreso: noviembre-2005
Mensajes: 144
Antigüedad: 18 años, 5 meses
Puntos: 2
Respuesta: como hacer un str_replace al crear un PDF

Código PHP:
Ver original
  1. class PDF_MySQL_Table extends FPDF
  2. {
  3. var $ProcessingTable=false;
  4. var $aCols=array();
  5. var $TableX;
  6. var $HeaderColor;
  7. var $RowColors;
  8. var $ColorIndex;
  9.  
  10. function Header()
  11. {
  12.     //Print the table header if necessary
  13.     if($this->ProcessingTable)
  14.         $this->TableHeader();
  15. }
  16.  
  17. function TableHeader()
  18. {
  19.     $this->SetFont('Arial','B',12);
  20.     $this->SetX($this->TableX);
  21.     $fill=!empty($this->HeaderColor);
  22.     if($fill)
  23.         $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
  24.     foreach($this->aCols as $col)
  25.         $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
  26.     $this->Ln();
  27. }
  28.  
  29. function Row($data)
  30. {
  31.     $this->SetX($this->TableX);
  32.     $ci=$this->ColorIndex;
  33.     $fill=!empty($this->RowColors[$ci]);
  34.     if($fill)
  35.         $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
  36.        
  37.     foreach($this->aCols as $col)
  38.        // esto agregue $data[$col['f']] = str_replace($find, $repl, $data[$col['f']]);
  39.         $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
  40.     $this->Ln();
  41.     $this->ColorIndex=1-$ci;
  42. }
  43.  
  44. function CalcWidths($width,$align)
  45. {
  46.     //Compute the widths of the columns
  47.     $TableWidth=0;
  48.     foreach($this->aCols as $i=>$col)
  49.     {
  50.         $w=$col['w'];
  51.         if($w==-1)
  52.             $w=$width/count($this->aCols);
  53.         elseif(substr($w,-1)=='%')
  54.             $w=$w/100*$width;
  55.         $this->aCols[$i]['w']=$w;
  56.         $TableWidth+=$w;
  57.     }
  58.     //Compute the abscissa of the table
  59.     if($align=='C')
  60.         $this->TableX=max(($this->w-$TableWidth)/2,0);
  61.     elseif($align=='R')
  62.         $this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
  63.     else
  64.         $this->TableX=$this->lMargin;
  65. }
  66.  
  67. function AddCol($field=-1,$width=-1,$caption='',$align='L')
  68. {
  69.     //Add a column to the table
  70.     if($field==-1)
  71.         $field=count($this->aCols);
  72.     $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
  73. }
  74.  
  75. function Table($query,$prop=array())
  76. {
  77.     //Issue query
  78.     $res=mysql_query($query) or die('Error: '.mysql_error()."<BR>Query: $query");
  79.     //Add all columns if none was specified
  80.     if(count($this->aCols)==0)
  81.     {
  82.         $nb=mysql_num_fields($res);
  83.         for($i=0;$i<$nb;$i++)
  84.             $this->AddCol();
  85.     }
  86.     //Retrieve column names when not specified
  87.     foreach($this->aCols as $i=>$col)
  88.     {
  89.        
  90.         if($col['c']=='')
  91.         {
  92.             if(is_string($col['f']))
  93.            
  94.                 $this->aCols[$i]['c']=ucfirst($col['f']);
  95.             else
  96.            
  97.                 $this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
  98.         }
  99.     }
  100.     //Handle properties
  101.     if(!isset($prop['width']))
  102.         $prop['width']=0;
  103.     if($prop['width']==0)
  104.         $prop['width']=$this->w-$this->lMargin-$this->rMargin;
  105.     if(!isset($prop['align']))
  106.         $prop['align']='C';
  107.     if(!isset($prop['padding']))
  108.         $prop['padding']=$this->cMargin;
  109.     $cMargin=$this->cMargin;
  110.     $this->cMargin=$prop['padding'];
  111.     if(!isset($prop['HeaderColor']))
  112.         $prop['HeaderColor']=array();
  113.     $this->HeaderColor=$prop['HeaderColor'];
  114.     if(!isset($prop['color1']))
  115.         $prop['color1']=array();
  116.     if(!isset($prop['color2']))
  117.         $prop['color2']=array();
  118.     $this->RowColors=array($prop['color1'],$prop['color2']);
  119.     //Compute column widths
  120.     $this->CalcWidths($prop['width'],$prop['align']);
  121.     //Print header
  122.     $this->TableHeader();
  123.     //Print rows
  124.     $this->SetFont('Arial','',11);
  125.     $this->ColorIndex=0;
  126.     $this->ProcessingTable=true;
  127.     while($row=mysql_fetch_array($res))
  128.     $this->Row($row);
  129.     $this->ProcessingTable=false;
  130.     $this->cMargin=$cMargin;
  131.     $this->aCols=array();
  132. }
  133. }

Probe lo de la codificación al row que me aconsejaste pero no funciono.

Este es el archivo mysql_table.php completo, en la function Row($data) se encuentra los datos en el array $data[$col['f']] pero a ponerle el srt_replace desaparecen las primeras dos columnas solo muestra la ultima.