PHP - Tcpdf And Data Lists
I want to produce a pdf document using mysql and TCPDF.
I can do this OK in some circumstances but I now have a problem. I have two tables - documents and parties - they are linked by a common field docid. I have for table documents, the fields: docid, doctitle, idcode and for the parties table: partyid, docid, party (the field party is the name of the party) For any document there could be any number of parties and for a single idcode there could be any number of documents. For example, for idcode = 12345 there might be 2 documents called doctitle 1 and doctitle 2. For doctitle 1 there are 3 parties to it party1, party 2 and party 3. For doctitle 2 there are two parties - party4 and party 5. For any idcode (which is passed through by the url) I want the pdf to give a list such as: Doctitle 1: party name 1 party name 2 party name 3 Doctitle 2: party name 4 party name 5 Part of my code is: mysql_select_db($database_process, $process); $result2 = mysql_query("SELECT parties.docid, GROUP_CONCAT(party SEPARATOR '<br>') AS partylist, documents.doctitle FROM parties INNER JOIN documents ON parties.docid=documents.docid WHERE parties.idcode = '$appidpassed' GROUP BY parties.docid LIMIT 1 ") or die(mysql_error()); while($row = mysql_fetch_array($result2)) { $doctitle = $row['doctitle']; $parties = $row['partylist']; } and then further down the page: $doctitle<br> $parties This only gives one document and the parties associated with it. I know the solution is probably easy but I can't see it. Does anyone have any ideas? Similar TutorialsHi all, I am trying to get data from MySQL to display in a html table in TCPDF but it is only displaying the ID. $accom = '<h3>Accommodation:</h3> <table cellpadding="1" cellspacing="1" border="1" style="text-align:center;"> <tr> <th><strong>Organisation</strong></th> <th><strong>Contact</strong></th> <th><strong>Phone</strong></th> </tr> <tbody> <tr>'. $id = $_GET['id']; $location = $row['location']; $sql = "SELECT * FROM tours WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { '<td>'.$location.'</td> <td>David</td> <td>0412345678</td> </tbody>'; } } '</tr> </table>'; Anyone got any ideas? Hi I have a table (applicant) and I am looking at producing a pdf displaying various items of data from this table. I have succeeded in getting the look I want but in my query I use a fixed applicantid (in this case an id of 4). What I want to be able to do is to have the id cary according to the url. In other words, when someone comes from one web page to this one and the url is of the format .../pdf_production.php?applicantid=42. I'm not sure I've explained that very well but I hope someone can help - I think this is the last thing I need to sort out. Many thanks in advance. The code I have so far is: <?php require_once('../Connections/process.php'); ?> <?php require_once('../tcpdf/config/lang/eng.php'); require_once('../tcpdf/tcpdf.php'); // get data from users table mysql_select_db($database_process, $process); $result = mysql_query("SELECT * FROM applicant WHERE applicantid = '4'"); while($row = mysql_fetch_array($result)) { $appid = $row['applicantid']; $idcode = $row['idcode']; $type = $row['type']; $company = $row['company']; $email = $row['email']; } // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); // create some HTML content $txt = <<<EOD Below are the details I require Company type: $type Company Name: $company Company email: $email EOD; // output the HTML content // $pdf->writeHTML($htmlcontent, true, 0, true, 0); $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0); // $pdf->writeHTML($inlinecss, true, 0, true, 0); // reset pointer to the last page // $pdf->lastPage(); //Close and output PDF document $pdf->Output('example_006.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ ?> I have a navigation list displaying which is a mix of html and php, everything is working fine however now I want to convert this block of code into a function but am having major problems with quotes. The line of code I currently have is $data = $db->query("SELECT * FROM menu")->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $row) { ?> <li><a href="<?php echo $row['url']; ?>" title="<?php echo $row['title']; ?>"><?php echo $row['icon'] . ' ' . $row['header']; ?></a></li> <?php } ?> As I say everything works using the above but now I am trying to echo the full li out and am having major issues with single and double quotes. I currently have echo "<li><a href='#' title='the title'><i class='fas fa-user site-nav--icon'></i> Help</a></li>"; Now I am trying to use the $row['url'], $row['title'], $row['icon'] & $row['header'] as per the top example but I cannot get the combination of quote marks correct, whether to use double, single or a combination. I would be grateful if someone could suggest the correct syntax for the a tag then I can work through the rest. Thanks I wanted to do auto numbering for my tables with css using TCPDF. I tried both ways but it does not work at all. I tried the one in the documentation of tcpdf and it does not work too. Can anyone give me a piece of advice on how to make this work? These are the both ways i mentioned and it did not work. $htmlcontent .=' <style> table { counter-reset: rowNumber; } table tr::before { display: table-cell; counter-increment: rowNumber; content: counter(rowNumber) "."; padding-right: 0.3em; text-align: right; } </style> <table id="receiptTable" cellpadding="3" style="max-height: 1000px;"> <tr> <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> </td> <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_title'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_sku'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['quantity'].' '.$irow['quantity_unit'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['product_buy_price'].' </td> <td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['purchase_price'].' </td> </tr> </table> '; }
for this i use the method of including external css into my tables but it does not work as well. I did make sure my file path is correct. (the code below) $htmlcontent .=' <style>.file_get_contents(css/receipt.css).</style> <table id="receiptTable" cellpadding="3" style="max-height: 1000px;"> <tr> <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> </td> <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_title'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_sku'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['quantity'].' '.$irow['quantity_unit'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['product_buy_price'].' </td> <td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['purchase_price'].' </td> </tr> </table> '; }
Hi I am trying to work out how to add a loop statement to my pdf generation (I think that's what I need). I have a mysql table - events with 3 fields - id, name and date. In my php page which is to generate the pdf I have: mysql_select_db($database_events, $events); $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE id>200 "); while($row = mysql_fetch_array($result)) { $id = $row['id']; $date = $row['date']; $name = $row['name']; } and in amongst the $html part of the page I have: $html ="<html> $id<br> $name<br> $date<br> <i>This is a test calendar.</i> This all works fine but (obviously) just gives one result. What do I need to add to make it list out all of the possible events? Many thanks in advance. Hi I am trying to add an image to a pdf file created using tcpdf. Part of the code I have to date is: $pdf->AddPage(); // create some HTML content $htmlcontent = "<html> <strong>THIS IS AN EXAMPLE TITLE<br></strong> <p> This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens This just some straight text that I've added to see what happens </p> <ol> <li>This is some example text for testing. <br> </li> <li>This is some example text for testing.</li> </ol> "; // output the HTML content $pdf->writeHTML($htmlcontent, true, 0, true, 0, ''); I have a logo which is in a folder and can be found at ../img/logo.png What I would like to do is have the image in the centre of the page before all of the text but whatever I've tried has failed. Any suggestions/answers would be much appreciated. Also I've failed at centering the title - any ideas on that. Many thanks. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=332698.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=323892.0 Hi,
I'm using TCPDF to create a PDF from a webpage.
This works great but I have the following problem:
I'm building in WordPress and as you may know WP saves images on different sizes. (e.g. 150x150, 300x300 and 1024x1024)
The thing I'm trying to create is that users can download a PDF ready for printing. So High Resolution images.
I use a preg_match_all function to match the image source and remove the additional image size from the filename so the original high resolution image is loaded.
e.g. image-150x150.jpg will be replaced by image.jpg.
So now the original image that has a image size of 6024x6024px and 300 DPI is loaded.
Then TCPDF uses a resize function that resizes the image back to 150x150 px but sets the DPI to 300 so it can be printed on a good quality.
This all works but now the problem comes:
If I do the preg_match_all function the image gets "pulled" from the rest of the content and looses it's position.
So my thought to fix this was. Get a preg_replace function and replace the image tag with a function that executes the whole image change like described above.
This doesn't work......
So i'm stuck here. Hope anyone can assist me with this.
Here is what I have done so far.
function execute(){ preg_match_all("/<img[^>]+src=(?:\"|\')\K(.[^\">]+?)(?=\"|\')/",$content,$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { $search = array('-'.$s1.'x'.$s2.'', '-'.$s3.'x'.$s4.'', '-'.$s5.'x'.$s6.''); $replace = array('', '', ''); $a = $matches[1][$i]; if (strpos($a,'-'.$s1.'x'.$s2.'') !== false) { $w = $s1; $w = $pdf->pixelsToUnits($w); $h = $s2; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '170'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s3.'x'.$s4.'') !== false) { $w = $s3; $w = $pdf->pixelsToUnits($w); $h = $s4; $h = $pdf->pixelsToUnits($h); $l = '217'; $l = $pdf->pixelsToUnits($l); $t = '20'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s5.'x'.$s6.'') !== false) { $w = $s5; $w = $pdf->pixelsToUnits($w); $h = $s6; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '310'; $t = $pdf->pixelsToUnits($t); } $content .= $pdf->Image(str_replace($search,$replace,$matches[1][$i]), $l, $t, $w, $h, 'JPG', '', '', true, 300, '', false, false, 0, false, false, false); } }; global $post; $id = $_GET['id']; $content_post = get_post($id);// get the content $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = preg_replace('/<img[^>]+./e',execute(), $content); // replace the image tag with the new image // EXPORT IT ALL $pdf->writeHTML($content, true, false, true, false, ''); Hi I have used TCPDF to generate documents with single values from a mysql table. Now I want to generate a calendar. I have a table events_pbw which contains (amongst others) the fields id, date and name. I would like to generate a pdf which lists all of the results for entries after a particular date (eg Jan 1st) I have this: // get data from events_pbw table $result = mysql_query("SELECT id, date, name FROM events_pbw WHERE `date` > 2011-01-01" "); while($row = mysql_fetch_array($result)) { $appid = $row['id']; $date = $row['date']; $name = $row['name']; } But I don't know how to get the full list of results into the pdf. I'm sure this is very easy but I'm not great on php coding! Does anyone have any examples or help they could give me? Many thanks This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331758.0
Hi, I have a table of content in my page. For each row it has a check box. How do i achieve the function of when i click on submit button, those rows which are checked will be downloaded as a single pdf file. For example, for each checked row is a PDF file here. Suppose if i checked for 5 rows , 5 PDFs will be downloaded. I haven't worked with TCPDF yet (PHP class for creating PDFs) but if anyone has, I'm just curious if you can reference an external CSS file to format the HTML that gets created in the PDF? Or can you only use inline CSS? Basically, I have a nicely formatted HTML table using a somewhat complicated external CSS file and I want to output that same table to a PDF and have it look essentially the same. If TCPDF cannot do this, do you know of any other PDF PHP libraries that can? Thanks, Greg Hi all!
I'm new here, apologies that my 1st post will be a cry for help. I'm tearing my hair out with this one.
I've got this page that generates PDF's via TCPDF plugin http://www.kinho.com/lightbox/ whenever I view it in chrome it zooms in at 100% to the top left corner. The problem is I need the images to be large and suitable to print (7"x5" or thereabouts) and so the PDF isn't built to be viewed at 100%, it just looks too zoomed in. Every other browser respects the fit to width setting. My images are 1600px on their long side, pages are landscape. here's the create.php:https://dl.dropboxusercontent.com/u/14123055/PHP/create.php
Can anybody advise a workaround for chrome? many thanks!
badger
Hi guys, I would like to display data from MySQL in the format of 5 lists (of one column each) one next to each other on a webpage I am quite good with SQL, but I lack knowledge about php and displaying data. SQL version: 5.1 Does anyone have any good website that would show how to do such a thing? Hi I have to multi select tables, the table on the left is field with the contents of an array, I then have it so the user can make there selections from the left box and move them into the right. They then hit submit and it gets stored inmysql table as an array. The problem I am having is keeping the selections in that right box after any sort of page refresh. Any ideas I have pasted the php and html code below, the add/remove function is controlled by javascript, I won't bother pasting that as i don't think it has anything to do with it. PHP ******** Code: [Select] <?php / ------- PARSING PERSONAL TRAINER DETAILS VENUE --------- if ($_POST['parse_var'] == "fromPool"){ $venue = $_POST['venue']; if (is_array($_POST['venue'])) { $venue = explode("\n", $_POST['venue']); } else { $venue = $_POST['venue']; } // Update the database data now here for all fields posted in the form $sqlUpdate = mysql_query("UPDATE ptdata SET venue='$venue' WHERE id='$id' LIMIT 1"); if ($sqlUpdate){ $success_msg = '<img src="images/Form/round_success.png" width="20" height="20" alt="Success" />Your venue information has been updated successfully'; } else { $error_msg = '<img src="images/Form/round_error.png" width="20" height="20" alt="Failure" /> ERROR: Problems arose during the information exchange, please try again later</font>'; } } // ------- END PARSING PERSONAL TRAINER DETAILS VENUE --------- ?> <?php ////////// Venue Array PHP For Multi Selection Boxes //////////// $dbString = ''; // To be pulled from Database $toPool = explode(',', $dbString); $pool = Array('Your Home','My Home','Outside','Private Studio','Your Work','Gym'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $toPool = (count($_POST['venue']) > 0)? $_POST['venue'] : Array(); $newDbString = implode(',', $toPool); // Store in Database; } $fromPool = array_diff($pool, $toPool); ?> html *********** <form action="ptmemberaccount.php" method="post" enctype="multipart/form-data"onsubmit="multipleSelectOnSubmit()"> <table width="500" align="left"> <tr> <td width="500" height="300" align="center"> <select multiple="multiple" name="fromBox[]" id="fromBox"> <?php foreach($fromPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> <select multiple="multiple" name="venue[]" id="toBox"> <?php foreach($toPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> </td> </tr> <tr> <td align="center" height="35"><script type="text/javascript"> createMovableOptions("fromBox","toBox",400,200,'Training Venues','Selected Training Venues'); </script> <p>Use the buttons to Add/Remove selections</p></td></td> </tr> <tr> <td align="center" height="100"> <input type="submit" value="OK"> </tr> </table> </form> If you need anymore info let me know, also if anyone knows a better way of achieving this i am open to suggestions. Many Thanks MOD EDIT: code tags added Hi, for uni i've got to make a shopping cart application in php/mysql. I'm almost done with it, managed to teach myself some nifty jquery and have been able to learn loads more PHP, I'm really enjoying it. I've come to a bit of a stand still though, I showed my application as it is to my lecturer and he had one little point. My application, you have lists, each list has its own categories (users can add, edit, delete their own) and in each category, there are items (which like categorys can be added, edited or deleted). So basically, you have a browse_list.php, which browses all the lists, each list has it's own unique hyperlink to browse_list_category.php?list_id= using the get method, it selects all the categories associated with that list, which, like browse_list.php have their own hyperlinks, but this time they link to browse_category_item.php?category_id= and they list what ever items are associated with that category. Sounds a mouth full, but it's really quite simple. I showed my lecturer that and he wasn't happy with the whole category/item layout. He said it would be better if the category list had a nested item list underneath it. He was happy with the whole list to category part with the hyperlink, though. Kinda like: Quote -list -------category -------item -list1 ------category1 ------item1 ------category2 ------item2 ------category3 ------item3 My database layout is tbllist -main list table, list_id, list_name tblcategory - main category table, category_id, category_name tblcategory_list - link table for list and category (many-many) list_id, category_id tblitem - main item table, item_id, item_name tbl_category_item - link table for category and item (many-many) category_id, item_id So, now you've kinda got the gist of what I'm doing.. I just need help with displaying each item in a category, under the category.. like a nested list <ul> <li>category 1</li> <ul> <li> item 1</li> <li> item 2</li> <li> item 3</li> </ul> </ul> I did try and have a go earlier, kinda rushed and managed to come up with this: <ul id="sortme" class="shoppinglist"> <?php // Split records in $result by table rows and put them in $row. while($row = mysql_fetch_array($result)) { echo '<li class="list" id="' . $row['category_id'] . '"><div class="text"><a href="browse_item_category.php?category_id=' . $row['category_id'] . '">' . $row['category_name'] . "</a></div> <div class=\"actions\"><a href=\"#\" class=\"tick\">Tick</a> <a href=\"categoryupdater.php?category_id=" . $row['category_id'] . "\" class=\"edit\">Edit</a><a href=\"#\" class=\"delete\">Delete</a></div> </li>\n"; } ?><ul id="sortme" class="shoppinglist"> <?php while($row = mysql_fetch_array($resultitem)) { echo '<li class="list" id="' . $row['item_id'] . '"><div class="text">' . $row['item_name'] . "</div> <div class=\"actions\"><a href=\"#\" class=\"tick\">Tick</a> <a href=\"itemupdater.php?item_id=" . $row['item_id'] . "\" class=\"edit\">Edit</a><a href=\"#\" class=\"delete\">Delete</a></div> </li>\n"; } ?> </ul> </ul> but this i get this not the whole list nested'ness it's a bit long winded I know but could anyone possible give me a hand? i've done pretty well so far not asking for help, but I think this is going to be the end of me! Hi I am having problems trying to view some data and wondered if anyone could help. I have a table called 'parties' which contains fields - partyid, docid and party. There is another table called 'documents' which has fields - docid and doctitle. I have a number of documents and for each document there are a number of parties - ie people linked to that document. What I would like to do is get a view on screen (and also printed out) that has the title of the document followed by a list of the parties associated with that document. For example, if in the documents table there was: |docid |doctitle | |1 |first document | |2 |second document| and in the parties table there was: |partyid |docid |party | |1 |1 |Fred | |2 |1 |Jim | |3 |1 |Jane | |4 |2 |Peter | |5 |2 |Fred | I could get a view that looked like: First document: Fred Jim Jane Second document: Peter Fred I suspect it may involve arrays but I have never used them so any guidance would be very welcome. Thanks |