Search the Community
Showing results for tags 'mysql php fpdf invoice'.
-
Hi there everyone. In this book Larry uses PayPal as a payment solution. I have different needs as my site will not work with a payment service. I want to output MYSQL data onto a PDF using the FPDF Library. I have looked around on the web and can't seem to find a understandable solution. Will somebody please help me with this? This solution below works perfectly with a text file, but I want a user to retrieve their monthly invoice by the click of a button. The .txt source must thus be substituted with MYSQL data. The problem is when I query MYSQL as usual, it gives the following error: FPDF error: Some data has already been output, can't send PDF file. Can anybody over here please help me with a workable solution? Thank you in advance! My Code is as follows: My Current data load function which usually takes a .txt file as parameter: function LoadData($file) { $lines = file($file); $data = array(); foreach($lines as $line) $data[] = explode(';',trim($line)); return $data; } This is a piece of my fpdf.php library which creates the columns: function ImprovedTable($header, $data) { $this->Ln(15); $this->SetFontSize(11); $w = array(20, 90, 20, 12, 50); // Header for($i=0;$i<count($header);$i++) $this->Cell($w[$i],7,$header[$i],1,0,'C'); $this->Ln(); // Data foreach($data as $row) { $this->SetFontSize(9); $this->Cell($w[0],9,$row[0],'LR',0,'C'); $this->Cell($w[1],9,$row[1],'LR',0,'C'); $this->Cell($w[2],9,$row[2],'LR',0,'C'); $this->Cell($w[3],9,$row[3],'LR',0,'C'); $this->Cell($w[4],9,$row[4],'LR',0,'C'); $this->Ln(); } // Closing line $this->Cell(array_sum($w),0,'','T'); } This is where the PDF is created. Here I'm still using the text file to get my data but want to use data from my table: $pdf=new PDF(); // Column headings $header = array('Ref #', 'Headline', 'Cost', 'Month', 'Date of transaction'); // Data loading $data = $pdf->LoadData('invoice.txt'); $pdf->SetFont('Arial','',14); $pdf->AddPage(); $pdf->ImprovedTable($header,$data); $pdf->Output(); This is the SQL Query that I tried to include in my PDF creater. The database connection is also include I have not added it here however, so that is not the problem. $query_database = "SELECT * FROM invoices WHERE user_number = '10'"; $connected_query = mysqli_query($connect_to_database, $query_database); while ($result = mysqli_fetch_array($connected_query)) { $invoice_data[] = $result; } foreach($invoice_data as $data);