Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/235075-tcpdf-and-data-lists/
Share on other sites

@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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.