Jump to content

hardbouw

New Members
  • Posts

    1
  • Joined

  • Last visited

hardbouw's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have been tasked to create an data entry and storage system for agents in a callcentre. I have no prior PHP knowledge. I have with he help of various online tutorials gotten a thing in place to insert data in to a mysql database and again display it in a table format. Our financial provider is not happy with he csv format I am sending the data in to him, they need an separate application form in an form format for each client. I now have to get each sale the agents made, ie each record individually populate an HTML Template I created which then in turn have to be converted to pdf. I searched around and none of the tutorials works for my situation, they all want to put all the data into an single table, I need each record in a separate table tried TCPDF, HTML2PDF and FPDF. All those only work with plain html data, however my whole application is written in PHP. This should be a simple fix for someone a bit more experienced in PHP. Here is my CODE: This works: <?php // server info $server = 'localhost'; $user = 'root'; $pass = 'password'; $db = 'debtdb'; // connect to the database $conn = new mysqli($server, $user, $pass, $db); // show errors (remove this line if on a live site) mysqli_report(MYSQLI_REPORT_ERROR); if(!isset($_POST['agentname'])) { $search_sql="SELECT * FROM daily"; $search_query=mysqli_query($conn, $search_sql); $search_rs=mysqli_fetch_assoc($search_query); } if(!empty($search_query)) { while($search_rs = mysqli_fetch_array($search_query)) { echo $search_rs["id"]; echo $search_rs["agentname"]; echo $search_rs["dateofsale"]; echo $search_rs["per_firstname"]; echo $search_rs["per_lastname"]; echo "<br>"; } } ?> This however do not, HTML2PDF (I truncated everything to simplify matters): <?php // server info $server = 'localhost'; $user = 'root'; $pass = 'password'; $db = 'debtdb'; // connect to the database $conn = new mysqli($server, $user, $pass, $db); // show errors (remove this line if on a live site) mysqli_report(MYSQLI_REPORT_ERROR); if(!isset($_POST['agentname'])) { $search_sql="SELECT * FROM daily"; $search_query=mysqli_query($conn, $search_sql); $search_rs=mysqli_fetch_assoc($search_query); } if(!empty($search_query)) { while($search_rs = mysqli_fetch_array($search_query)) { $content = " <page> echo $search_rs["id"]; echo $search_rs["agentname"]; echo $search_rs["dateofsale"]; echo $search_rs["per_firstname"]; echo $search_rs["per_lastname"]; echo "<br>"; </page>"; require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php'); $html2pdf = new HTML2PDF('P','A4','fr'); $html2pdf->WriteHTML($content); $html2pdf->Output('exemple.pdf'); } } ?> TCPDF: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1>View Records</h1> <?php // connect to the database include('connect-db.php'); // get the records from the database if ($result = $mysqli->query("SELECT * FROM clients ORDER BY id")) { // display records if there are records to display if ($result->num_rows > 0) { // set table headers //PDF Generating Start // Include the main TCPDF library <body> <h1>View Records</h1> <?php // connect to the database include('connect-db.php'); // get the records from the database if ($result = $mysqli->query("SELECT * FROM clients ORDER BY id")) { // display records if there are records to display if ($result->num_rows > 0) { //PDF Generating Start // Include the main TCPDF library (search for installation path). require_once('examples/tcpdf_include.php'); include('tcpdf.php'); // create new PDF document $pdf = new TCPDF('L', PDF_UNIT, 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Asimegroup'); $pdf->SetTitle('Asime Loan App'); $pdf->SetSubject('Asime Loan Application Form'); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins('5', '0', '0'); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, '0'); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'examples\lang\eng.php')) { require_once(dirname(__FILE__).'examples\lang\eng.php'); $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $html = ' <body> <br/> <table> <tr> <td height="40px"></td> </tr> <tr> <td align="right" class="heading" width="175px">Personal</td> <td align="left" class="heading" width="210px">Details:</td> <td width="10px"></td> <td align="right" class="heading" width="150px">Relative not</td> <td align="left" class="heading" width="170px">living with you:</td> <td width="10px"></td> <td align="right" class="heading" width="185px">Expenses:</td> <td width="100px"></td> </tr> <tr> <td class="subheading">SA Citizen?:</td> <td class="data"></td> <td></td> <td class="subheading">Name:</td> <td class="data"></td> <td></td> <td class="subheading">Bond / Rent:</td> <td class="data"></td> </tr> <tr> <td class="subheading">Name:</td> <td class="data">' . $per_firstname . '</td> <td></td> <td class="subheading">Surname:</td> <td class="data">' . $per_lastname . '</td> <td></t d> <td class="subheading">Rates, Water, Electricity:</td> <td class="data"></td> </tr> </table>'; // output the HTML content $pdf->writeHTML($html, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('Asime_Loan'.$per_id.'.pdf', 'F'); //PDF Generating End } } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query // close database connection $mysqli->close(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.