I'm using PHP to output address details to a PDF which is formatted to match an avery label layout and am just struggling with the final part of my coding.
When i use the following code everything works fine.
but if the data for a particular field doesn't exist there is a gap in the flow of the address, so the address label appears along the lines of:PHP Code:do {
$DueSweepDate = strftime('%d / %m / %Y',$row ['NextSweepDate']);
$text = sprintf("%s %s\n%s %s\n%s\n%s\n%s\n%s\n\nCustID: %s\nDue Sweep Date: %s", $row['FirstName'] ,$row['Surname'], $row['HouseNumber'] ,$row['Address1'], $row['Address2'], $row['Address3'], $row['TownCity'], $row['PostCode'], $row['CustID'], $DueSweepDate);
$pdf->Add_Label($text);
} while ($row = mysql_fetch_array($result));
echo $text;
$pdf->Output();
Persons Name
Address line 1
Adress line 3
Town or City
Postcode
In order to remove any additional liines so the address layout flows properly i felt i needed to generate the $text variable dynamically as the data is ploughed through.
This is what i have ended up with after playing around a little
i'm still learning php so there may be glaring errors in there but i just can't quite get the code to working.PHP Code:$DueSweepDate = strftime('%d / %m / %Y',$row ['NextSweepDate']);
$vars = "%s %s";
if ($row['HouseNumber'])$vars .='\n%s';
if ($row['Address1'])$vars .=' %s';
if ($row['Address2'])$vars .='\n%s';
if ($row['Address3'])$vars .='\n%s';
if ($row['TownCity'])$vars .='\n%s';
if ($row['PostCode'])$vars .='\n%s';
$vars .='\n';
if ($row['CustID'])$vars .='\nCustID: %s';
if ($row['NextSweepDate'])$vars .='\nDue Sweep Date: %s';
$data = $row['FirstName'];
$data .= ',' .$row['Surname'];
if ($row['HouseNumber'])$data .= ',' . $row['HouseNumber'];
if ($row['Address1'])$data .= ', ' . $row['Address1'];
if ($row['Address2'])$data .= ', ' . $row['Address2'];
if ($row['Address3'])$data .= ', ' . $row['Address3'];
if ($row['TownCity'])$data .= ', ' . $row['TownCity'];
if ($row['PostCode'])$data .= ', ' . $row['PostCode'];
if ($row['CustID'])$data .= ', ' .$row['CustID'];
if ($row['NextSweepDate'])$data .= ', ' . $DueSweepDate;
$text = sprintf('"'.$vars.'"' .",".($data));
$pdf->Add_Label($text);
} while ($row = mysql_fetch_array($result));
$pdf->Output();
If you can see what i am trying to achieve can anyone offer me some advice and direction with this?
Thanks
James






Bookmarks