Hi
I work with a program that show information about customers that how many times they have bought something and show it for each customer in a pdf file.Customer information is saved in a text file.Instead of comparing a file with itself I’ve created two text file that both of them have the same contents.The program works for creating text files but it creates pdf file just for the first line.
Could you help me with it?
Thanks.
[php]
<?php $handle = fopen($PDFfile, "r")or die ("Unable to open file PDFfile-handle!"); $handle_temp = fopen($PDFfile_temp, "r")or die ("Unable to open file handle_temp!"); if ($handle) { while(!feof($handle)) { $line = fgets($handle,4096); list ( $cust_name, $cust_mobile, buy_list, $time_date, $bill) = explode(",",trim($line)); $telnr = $cust_mobile; //create a text file for each customer $PDFfile_cust_mobile='/bla/bla/pdf/'.$cust_mobile.'_'.date("Y.m.d_H.i.s").'.txt'; $handle_cust_mobile = fopen($PDFfile_cust_mobile,'a')or die ("Unable to open file!"); fputs($handle_cust_id,$line); while(!feof($handle_temp)) {//compare first line in PDFfile with PDFfile_temp $line_temp = fgets($handle_temp,4096); list ($cust_name_temp, $cust_mobile_temp, $buy_list_temp, $time_date_temp, $bill_temp) = explode(",",trim($line_temp)); $telnr_temp = $cust_mobile_temp; if($telnr == $telnr_temp) fputs($handle_telnr,$line_temp); } fclose($handle_telnr); class PDF extends FPDF { function LoadData($file){ $lines = file($file); $data = array(); foreach($lines as $line) $data[] = explode(',',trim($line)); return $data;} function ImprovedTable($header, $data){ $w = array(30,30,30,18,19); for($i=0;$iCell($w[$i],7,$header[$i],1,0,'C'); $this->Ln(); foreach($data as $row) { $this->Cell($w[0],6,$row[0],'LR'); $this->Cell($w[1],6,$row[1],'LR'); $this->Cell($w[2],6,$row[2],'LR'); $this->Cell($w[3],6,$row[3],'L'); $this->Cell($w[4],6,$row[4],'L'); $this->Ln(); } $this->Cell(array_sum($w),0,'','T');} } $pdf = new PDF(); $header =array ('Customer_name','Mobile','buy','Time_date','Bill'); $data = $pdf->LoadData('/bla/bla/pdf/'.$telnr.'_'.date("Y.m.d_H.i.s").'.txt'); $pdf->SetFont('Arial','',8); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->ImprovedTable($header,$data); $pdf->SetFont( 'Arial', '', 11 ); $pdf->output('/bla/bla/pdf/'.$telnr.'_'.date("Y.m.d_H.i.s").'.pdf'); }//end of while }// end of if fclose($handle); fclose($handle_temp); ?>[/php]