Refael
asked on
fpdf row title
Hello Experts,
Trying to understand how fpdf works... not easy....
all the examples i could find with mysql are tables with column headers.
i need something like this:
Names of partners: $name1, $name2, $name3
when the WHILE loops only on the variables AND not keep repeating the " Names of partners:"
here is part of the code from where i loop. i tired many variations with no luck.
while($row = mysql_fetch_array($result)) {
$partner_fname = $row['partner_fname'];
$partner_lname = $row['partner_lname'];
$ownerName = "Owner`s Name: ". $partner_fname. $partner_lname;
$i = 0;
$pdf->Cell(0,10,$ownerName, 0, 10);
$i = $i + 1;
ASKER
Hi hielo
thank you! the only problem i still have is to have keep the two variables in the same line e.g. $name1, $name2, $name3. currently they appear line after line break. i tried this but it still does not work.
$pdf->Cell(0,10,$ownerName
Something like this should work:
Also have a look at this for more stylish text output:
http://www.fpdf.org/en/tut orial/tuto 6.htm
$pdf->Write("Owner's Name: ");
$numberOfRows = mysql_num_rows($sql);
$rowNumber = 1;
while($row = mysql_fetch_array($result)) {
$pdf->Write( $row['partner_fname'] . " " . $row['partner_lname']);
// Output comma between names
if($rowNumber < $numberOfRows)
{
$pdf->Write( ", " );
}
}
Also have a look at this for more stylish text output:
http://www.fpdf.org/en/tut
ASKER
johannod thanks, but this brings some errors in regards to the write function.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ray_Paseur... your knowledge in almost every 'zone' i posted in is incredible!
this line $string .= "$row['partner_fname'] $row['partner_lname'],"; have a problem so i removed the quotes but now it prints the name right after the other without the "," nor space.
thanks!
thank you! the only problem i still have is to have keep the two variables in the same line e.gIt sounds like some of those items may have trailing newlines. Try:
...
if( 0==mysql_num_rows($result) )
{
echo 'No results found';
}
else
{
$row = mysql_fetch_assoc($result);
$ownerName=array();
while($row = mysql_fetch_assoc($result))
{
$ownerName[]= trim($row['partner_fname']). ' ' .trim($row['partner_lname']);
}
$ownerName='Owner`s Name: '.implode('', $ownerName);
$pdf->Cell(0,10,$ownerName, 0, 0);
}
@hielo: Good idea about using trim() on the variables. In the snippet at ID:36502452 is line 8 extraneous? Also the implode on line 14 might need a comma between the quotes like implode(',', $ownerName)
>>In the snippet at ID:36502452 is line 8 extraneous?... comma...
Good catch. I copied from my original post and completely missed that fetch() after changing from do{}while() to while().
Good catch. I copied from my original post and completely missed that fetch() after changing from do{}while() to while().
...
if( 0==mysql_num_rows($result) )
{
echo 'No results found';
}
else
{
$ownerName=array();
while($row = mysql_fetch_assoc($result))
{
$ownerName[]= trim($row['partner_fname']). ' ' .trim($row['partner_lname']);
}
$ownerName='Owner`s Name: '.implode(', ', $ownerName);
$pdf->Cell(0,10,$ownerName, 0, 0);
}
...knowledge in almost every 'zone' i posted in is incredible!
Thanks for your kind words. I only pay attention to the PHP zone, but with the way EE works with multi-zone postings I may appear to be in two places at once ;-)
Thanks for your kind words. I only pay attention to the PHP zone, but with the way EE works with multi-zone postings I may appear to be in two places at once ;-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Guys, thank you all so much!
i am learning... that's good :-) now, i am trying to add the next line. e.g.:
Names of partners: $name1, $name2, $name3
Company Emails: $email1, $email2, $email3
i am trying to add the next line learning from your examples and i get something like this:
Names of partners: $name1, Company Emails: $email1.....
can you please direct me. if find this fpdf very confusing and not really easy!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>$email[]= trim($row['email']);
should have been $emails...
should have been $emails...
...
if( 0==mysql_num_rows($result) )
{
echo 'No results found';
}
else
{
$ownerName=array();
$emails=array();
while($row = mysql_fetch_assoc($result))
{
$ownerName[]= trim($row['partner_fname']). ' ' .trim($row['partner_lname']);
$emails[]= trim($row['email']);
}
$ownerName='Owner`s Name: '.implode(', ', $ownerName);
$pdf->Cell(0,10,$ownerName, 0, 0);
$emails='Company Emails: '.implode(', ', $emails);
$pdf->Cell(0,10,$emails, 0, 0);
}
ASKER
hielo thank you. i feel like this would never end....
i took you script and run it....
if the company have 3 owners and only 1 email it prints the email 3 times....
just tell me if i this is a problem in the mysql select and not the script.
It sounds like each of those owners are using the same email OR your query is wrong. If you think the query is correct and you want unique email list, then change:
$emails='Company Emails: '.implode(', ', $emails);
to:
$emails='Company Emails: '.implode(', ', array_unique($emails) );
BUT, if your db has (like I said, "It sounds like each of those owners are using the same email" ):
John, a@b.com
Sally, a@b.com
Mary, X@b.com
then using the array_unique() fix, will result in:
John, Sally, Mary
a@b.com, X@b.com
making it seem as if though Sally "owns" X@b.com and Mary doesn't have an email. I don't know about you, but given that specific example I would rather have:
John, Sally, Mary
a@b.com, a@b.com, X@b.com
$emails='Company Emails: '.implode(', ', $emails);
to:
$emails='Company Emails: '.implode(', ', array_unique($emails) );
BUT, if your db has (like I said, "It sounds like each of those owners are using the same email" ):
John, a@b.com
Sally, a@b.com
Mary, X@b.com
then using the array_unique() fix, will result in:
John, Sally, Mary
a@b.com, X@b.com
making it seem as if though Sally "owns" X@b.com and Mary doesn't have an email. I don't know about you, but given that specific example I would rather have:
John, Sally, Mary
a@b.com, a@b.com, X@b.com
ASKER
hi hielo, thank you, thank you...
i am trying the mysql query in phpmyadmin... the problem is solved having the array_unique. the problem was not in query... for some reason it was printing the same email 3 times...
the problem in query is that i have 3 WHERE statements and when one return false unfortunately i have a blank page. i should i guess create multiple sql queries.
>>hi hielo, thank you, thank you...
You are welcome.
You are welcome.
ASKER
Guys, special thank you for all the experts! i wish i could give each of you 500 points!
Try:
Open in new window