aadebayo 0 Newbie Poster

Hello

I have managed to get the pdf working. There is a problem though, I need 2 records to be displayed on every row, instead of just one. In getting 2 records to display, I created a table with a row and 2 columns, then using a counter variable to check if the record is an even record or odd record, I determine where each record goes. The problem is that an error message is thrown when doing this. The error message is FPDF error: Some data has already been output, can't send PDF file (output started at /home/w/e/weststreet/web/public_html/MembersDBLive/reports/testCopy.php:162)
It happens at line 162 (bolded)


Below is the code

<?php
require('fpdf17/fpdf.php');

require('../db_config.php');
require('../global.php');
// connect to the database
db_connect($mysql['username'], $mysql['password'], $mysql['database'],$mysql['host']);

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$memberRecord = mysql_query("select `members_HouseGroup`.`description` AS `description`,`members_HouseGroup`.`id` AS `housegroupID`,`members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, members_memberType.description as MemberType from ((`members_users` left join`members_memberType` on((`members_memberType`.`id` = `members_users`.`memberTypeID`))) left join `members_HouseGroup` on((`members_HouseGroup`.`id` = `members_users`.`housegroupID`))  ) where ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) ) and username not in (select username from members_spouseLink) order by members_users.lastname "); 
$number=mysql_num_rows($memberRecord);
$amp = "&";
$countRec = 0;
$space = "nbsp;nbsp;" ;
//echo "number of records are $number";
while (($rowMember = mysql_fetch_array($memberRecord)) != false) {
    $id = $rowMember['id'];
    //echo "ID is {$id}";    
    $name = $rowMember['firstname'].' '.$rowMember['lastname'];
    $firstname = $rowMember['firstname'];
    //echo "name again is $name";
    $spfirstname = $rowMember['spfirstname'];
    $lastname = $rowMember['lastname'];
    $country = $rowMember['country'];
    $phone = $rowMember['phone'];
    $address1 = $rowMember['address1'];
    $address2 = $rowMember['address2'];
    $town = $rowMember['towns'];
    $PostCode = $rowMember['postCode'];
    $homephone = $rowMember['homephone'];
    $homephoneText = "phone: ";
    $homephone = $homephoneText.$homephone;
    $businessphone = $rowMember['businessphone'];
    $mobilephone = $rowMember['mobilephone'];
    $mobilephoneText = "mobile: ";
    $mobilephone = $mobilephoneText.$mobilephone;
    $email = $rowMember['email'];
    $emailText = "email: ";
    $email = $emailText.$email;
    $busemail = $rowMember['busemail'];
    $nextkin = $rowMember['nextkin'];
    $memberTypeDesc = $rowMember['MemberType'];
    $houseGroup = $rowMember['description'];
    $username = $rowMember['username'];
    //$child = $rowMember['child'];
    //echo " username pulled is $username";
    //echo "<td class='style2'>$name</td>";
    $houseGroupLeader1 = $rowMember['HouseGroupLeader1'];
    //echo "houseGroupLeader1 is {$houseGroupLeader1}";
    $countRec = $countRec + 1;
 //echo "Record number is $countRec";


// first let us populate the temp tables for this session
//$sqlTempMin="insert into vwMembersMinistryDetails  select '$session', `mu`.`id` AS `id`,`mu`.`username` AS `username`,`mu`.`firstname` AS `firstname`,`mu`.`email` AS `email`,`mu`.`lastname` AS `lastname`,`mu`.`memberTypeID` AS `memberTypeId`,`mm`.`name` AS `MinistryName`,`mmr`.`name` AS `RoleName`, '$admin' from (((`members_users` `mu` left join `members_ministryParticipant` `mmp` on((`mu`.`id` = `mmp`.`membersID`))) left join `members_Ministry` `mm` on((`mm`.`id` = `mmp`.`ministryID`))) left join `members_Ministry_Role` `mmr` on((`mmr`.`id` = `mmp`.`roleID`))) where (`mu`.`memberTypeID` > 1 ) and `mm`.`name` is not null "; 
//$resultTempMin = mysql_query($sqlTempMin) or die(mysql_error()); 

$membersSpouse = mysql_query("SELECT firstname,email,mobilephone FROM members_users where username in (select username from members_spouseLink where spouseUserID='$username')");
while (($rowMemberSpouse = mysql_fetch_array($membersSpouse)) != false) {
$spfirstname = $rowMemberSpouse['firstname'];
$amp = " & ";
$firstname = $firstname.$amp.$spfirstname;
if (!empty($spfirstname)) {
    $lenFirstname = strlen($firstname);
    if ($lenFirstname < 10) {
        $lenFirstname = strlen($firstname) + lenFirstname + 10;
    }
    else
    {
        $lenFirstname = strlen($firstname) + 20;
    }
    }
else
    {
$lenFirstname = strlen($firstname) + 5;
    }
$spemail = $rowMemberSpouse['email'];
$emailText = "email: ";
$spemails = $emailText.$spemail;
$spMobile = $rowMemberSpouse['mobilephone'];
$mobilephoneText = "mobile: ";
$spMobiles = $mobilephoneText.$spMobile;
}
$sqlchild = "select `members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, group_concat(members_child.cfirstname  ORDER BY members_child.dateOfBirth SEPARATOR ' , ') as child from ((`members_users`  inner join members_child  on (members_child.username=members_users.username) ) ) where members_child.username = '$username' and ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) )  group by members_users.lastname";
//echo "children select statement is $sqlchild";
$memberChildRecord = mysql_query("select `members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, group_concat(members_child.cfirstname  ORDER BY members_child.dateOfBirth SEPARATOR ' , ') as child from ((`members_users`  inner join members_child  on (members_child.username=members_users.username) ) ) where  members_child.username = '$username' or members_child.username1 = '$username'  and ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) )  group by members_child.username");

//$amp = "&";
if (mul($counter) == FALSE) 
{
echo "<table>";
echo "<tr>";
echo "td";

$lenLastname = strlen($lastname) + 12;
$lenSpfirstname = strlen($spfirstname) + 12;
$lenAmp = strlen($amp) + 5;



$pdf->Cell($lenFirstname,5, $firstname);
$pdf->Cell($lenLastname,5, $lastname);
$pdf->Ln( 4 );
 
 while (($rowChild = mysql_fetch_array($memberChildRecord)) != false) {
    $numberChild=mysql_num_rows($memberChildRecord);
    $leftBrac = "(";
    $rightBrac = ")";
    $child = $rowChild['child'];
    $child = $leftBrac.$child.$rightBrac;

    $pdf->Cell(30,5, $child);
    $pdf->Ln( 4 );
    }
    
    
$pdf->Cell(30,5, $address1);
$pdf->Ln( 4 );
    if (!empty($address2))
    {
        $pdf->Cell(30,5, $address2);
        $pdf->Ln( 4 );
    }
$pdf->Cell(30,5, $town);
$pdf->Ln( 4 );
$pdf->Cell(30,5, $PostCode);
$pdf->Ln( 4 );
    if (!empty($rowMember['homephone']))
    {
        $pdf->Cell(30,5, $homephone);
        $pdf->Ln( 4 );
    }
    if (!empty($rowMember['mobilephone']))
    {
        $pdf->Cell(30,5, $mobilephone);
        $pdf->Ln( 4 );
    }
    if (!empty($spMobiles))
     {
         $pdf->Cell(30,5, $spMobiles);
         $pdf->Ln( 4 );
     }
    if (!empty($rowMember['email']))
    {
        $pdf->Cell(30,5, $email);
        $pdf->Ln( 4 );
    }
    if (!empty($spemail))
     {
         $pdf->Cell(30,5, $spemails);
         $pdf->Ln( 4 );
     }
    
//}

echo "</td>";
}
else
{
[B]echo "<td>";[/B]

$lenLastname = strlen($lastname) + 12;
$lenSpfirstname = strlen($spfirstname) + 12;
$lenAmp = strlen($amp) + 5;



$pdf->Cell($lenFirstname,5, $firstname);
$pdf->Cell($lenLastname,5, $lastname);
$pdf->Ln( 4 );
 
 while (($rowChild = mysql_fetch_array($memberChildRecord)) != false) {
    $numberChild=mysql_num_rows($memberChildRecord);
    $leftBrac = "(";
    $rightBrac = ")";
    $child = $rowChild['child'];
    $child = $leftBrac.$child.$rightBrac;

    $pdf->Cell(30,5, $child);
    $pdf->Ln( 4 );
    }
    
    
$pdf->Cell(30,5, $address1);
$pdf->Ln( 4 );
    if (!empty($address2))
    {
        $pdf->Cell(30,5, $address2);
        $pdf->Ln( 4 );
    }
$pdf->Cell(30,5, $town);
$pdf->Ln( 4 );
$pdf->Cell(30,5, $PostCode);
$pdf->Ln( 4 );
    if (!empty($rowMember['homephone']))
    {
        $pdf->Cell(30,5, $homephone);
        $pdf->Ln( 4 );
    }
    if (!empty($rowMember['mobilephone']))
    {
        $pdf->Cell(30,5, $mobilephone);
        $pdf->Ln( 4 );
    }
    if (!empty($spMobiles))
     {
         $pdf->Cell(30,5, $spMobiles);
         $pdf->Ln( 4 );
     }
    if (!empty($rowMember['email']))
    {
        $pdf->Cell(30,5, $email);
        $pdf->Ln( 4 );
    }
    if (!empty($spemail))
     {
         $pdf->Cell(30,5, $spemails);
         $pdf->Ln( 4 );
     }
    
//}



echo "</td>";
}
$pdf->Ln();
$pdf->Output();
}

function mul($x){
    if ($x % 2 == 0) {
        return TRUE;
    }else{
        return FALSE;
    }
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.