TCPDF and table joins

I have produced pdfs before using TCPDF but they have all used results from 1 table. Now I want to get data from two tables - applicant and finance which are linked by the applicantid field.

Part of the code is:


mysql_select_db($database_process, $process);
$result = mysql_query("SELECT  applicantid, idcode, type, company, email, concat_ws('<br/>',case when coalesce(add1,'')>''then add1 end,case when coalesce(add2,'')>''then add2 end, case when coalesce(town,'')>''then town end,case when coalesce(postcode,'')>'' then postcode end) as address, DATE_FORMAT(applicationdate,'%D %M %Y') AS fDate, CONCAT(forename,' ',surname) AS name
                    FROM applicant INNER JOIN finance ON finance.applicantid=applicant.applicantid
                    WHERE idcode = '$appidpassed'
                    LIMIT 1
                    "); 

while($row = mysql_fetch_array($result)) 
  { 
    $appid = $row['applicantid']; 
    $idcode = $row['idcode']; 
	$type = $row['type']; 
    $company = $row['company']; 
    $email = $row['email']; 
	$address = $row['address'];
	$printdate = $row['fDate'];
	$apname = $row['name'];
} 
   

But when I run this I get an error something like:
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in — .php on line 68

Line 68 is the line
while($row = mysql_fetch_array($result))

What am I doing wrong?

I would guess your query failed, check [fphp]mysql_error[/fphp] for more info. :slight_smile:

There’s probably a problem with the query.

Try this:


mysql_select_db($database_process, $process);
$result = mysql_query("SELECT  applicantid, idcode, type, company, email, concat_ws('<br/>',case when coalesce(add1,'')>''then add1 end,case when coalesce(add2,'')>''then add2 end, case when coalesce(town,'')>''then town end,case when coalesce(postcode,'')>'' then postcode end) as address, DATE_FORMAT(applicationdate,'%D %M %Y') AS fDate, CONCAT(forename,' ',surname) AS name
                    FROM applicant INNER JOIN finance ON finance.applicantid=applicant.applicantid
                    WHERE idcode = '$appidpassed'
                    LIMIT 1
                    ") or die(mysql_error()); 

This will show the mysql error if something goes wrong.

Edit: Anthony beat me to it yet again :slight_smile:

So simple - showed me the erros and fixed easily.

Many thanks