tommy2shoes Posted April 29, 2011 Share Posted April 29, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235075-tcpdf-and-data-lists/ Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 Quote Link to comment https://forums.phpfreaks.com/topic/235075-tcpdf-and-data-lists/#findComment-1208116 Share on other sites More sharing options...
tommy2shoes Posted April 29, 2011 Author Share Posted April 29, 2011 Sorry, if it isn't clear, I want to know how to get all documents associated with a specific idcode, and its linked parties, printed out in a pdf using TCPDF and with the tables and fields as described in the first part. I can only get one printed. Quote Link to comment https://forums.phpfreaks.com/topic/235075-tcpdf-and-data-lists/#findComment-1208126 Share on other sites More sharing options...
mikosiko Posted April 29, 2011 Share Posted April 29, 2011 @tommy... what fugix was trying to tell you is to enclose your code using the available tags in the editor to make it clear to read by others doing that your example code should looks like this: ... better right? 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']; } Now, you can use 2 sources to get the idea of how to solve your issue: a) this post from PFMAbisMad will show you how to work in your while loop to produce the expected results (look for the Reply#6, obviously you must adjust the code to your problem) (EDIT: I just noticed that you are using GROUP_CONTACT, therefore this part could not be necessary but good to know) and b) the TCPDF documentation and examples to produce the final result... specially take a look to the example #48 that looks appropriated for this case. In addition, you mentioned that you can see only one printed... most likely is because you are using LIMIT 1 in your select and that could be the only problem that you have. good luck Quote Link to comment https://forums.phpfreaks.com/topic/235075-tcpdf-and-data-lists/#findComment-1208213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.