Jump to content

Recommended Posts

Hello,

 

So I've been stuck on this problem for a few days now and I'm hoping for some help.  Here is what I have done.  I created a MySQL database with my companies products in it.  With all the information.  We sell laptop batteries and power supplies.  We have around 500 products and adding more almost every other week.  We are getting ready to list our products on larger websites such as QVC and the like.  They are looking for a PDF file that contains all the information in it so there copy write team can put it on the site.  Anyway instead of having to manually format 500 files I figured that I could do this using good ol PHP.  I did some searching and found the FPDF class and loaded it up.  I was able to do EVERYTHING I wanted except for when I got to the end.  What I was trying to do is have the compatible models list in a column on the left and list of compatible codes in a column on the right hand side.  However as soon as it gets to the end of the page all the subsequent items create a complete new page.  Thinking this option is not going to work I went to try and use the fopen but it does not like my trying to echo my MySQL statements.  Does anyone have a better approach to this.  I've been driving myself nuts and I need to have these documents in another day or two.

They are looking for a PDF file that contains all the information in it so there copy write team can put it on the site.

*Headdesk*

 

Set up an API do export it as JSON or XML, or even CSV. It's trivial to have a web site import any of those formats, and a LOT more sane than exporting to PDF for then to manually type it into the DB.

That whole PDF issue just reeks of wooden tables.

Christian's advice is good - contact them about alternative export formats to make their life easier.

 

However, in the event they still insist on PDF, let us what do you want to happen at the end of the page and what is your current code to create the pages?

Well as a company we would like to have a spec sheet on each of our products anyway.  Also the other issue is some of those sites limit the amount of characters we can put into the description and we have quite a few that exceed that limit.  That's why they said give us a PDF file that we can attach and the customer can open that to see if there model is listed if its not able to fit on the page.  Thats why I'm trying to do it this way.  I posted the link.  Here is the code I have written.

 

 

<?PHP

require('fpdf.php');

require('databaseconnect.php');

 

 

if ($db_found) {

 

$SQL = "SELECT * FROM product_info WHERE SKU = 'DQ-BTPANJ1-6'";

$result = mysql_query($SQL);

 

$num=mysql_numrows($result);

 

$num=$num-2;

 

$db_field = mysql_fetch_assoc($result);

 

$filename = $db_field{'SKU'} . '.pdf';

$filename = str_replace('/','',$filename);

$filename = 'pdfs/' . $filename;

 

$pic = $db_field{'SKU'} . '-1200.jpg';

$pic = str_replace('/', '', $pic);

$pic = 'denaqimages/' . $pic;

 

$models = $db_field['Compatible_Models'];

$models = explode(",",$models);

sort($models);

 

$oemcodes = $db_field['OEM_Part_Numbers_Codes'];

$oemcodes = explode(",",$oemcodes);

sort($oemcodes);

 

 

$pdf = new FPDF();

$pdf->AddPage();

$pdf->SetFont('Times','B',14);

$pdf->Image('denaq.jpg',10,10,60);

$pdf->Image($pic,160,5,40);

$pdf->Cell(10,40,'Model #' . $db_field['SKU']);

$pdf->SetXY(10,10);

$pdf->Cell(0,50,'UPC  #' . $db_field['UPC']);

$pdf->SetXY(10,45);

$pdf->SetFont('Times','',14);

$pdf->Write(5,$db_field['Collection_Ad_Copy'] .'  ' . $db_field['Paragraph_description']);

$pdf->SetXY(10,65);

$pdf->SetFont('Times','B',14);

$pdf->Cell(0,20,'Features:');

 

$pdf->SetFont('Times','',14);

 

$pdf->SetXY(20,80);

$pdf->Cell(30,10,'- ' . $db_field['Feature_1']);

 

$pdf->SetXY(20,85);

$pdf->Cell(30,10,'- ' . $db_field['Feature_2']);

 

$pdf->SetXY(20,90);

$pdf->Cell(30,10,'- ' . $db_field['Feature_3']);

 

$pdf->SetXY(20,95);

$pdf->Cell(30,10,'- ' . $db_field['Feature_4']);

 

$pdf->SetXY(10,100);

$pdf->SetFont('Times','B',14);

$pdf->Cell(0,20,'Specifications:');

 

$pdf->SetFont('Times','',14);

$pdf->SetXY(20,115);

$pdf->Cell(30,10,'- ' . $db_field['Cell_Count'] .' Lithium Ion Cells');

 

$pdf->SetXY(20,120);

$pdf->Cell(30,10,'- ' . $db_field['Specification_3']);

 

$pdf->SetXY(20,125);

$pdf->Cell(30,10,'- Capacity: ' . $db_field['Capacity_mAh'] . ' / ' . $db_field['Capacity_Whr']);

 

$pdf->SetXY(20,130);

$pdf->Cell(30,10,'- Length: ' . $db_field['Product_Length'] . 'in X Width: ' . $db_field['Product_Width'] . 'in X Height: ' . $db_field['Product_Height'] . 'in');

 

$pdf->SetFont('Times','B',14);

$pdf->SetXY(10,145);

$pdf->Cell(20,10,'Replaces the following ' . $db_field['Brands'] . ' models:');

 

$pdf->SetFont('Times','',14);

$row_height = 5;

$y_axis = 156;

 

$i=0;

while($i < count($models)) {

$pdf->SetY($y_axis);

$pdf->SetX(100);

$pdf->MultiCell(150,5,$models[$i]);

$pdf->Ln(1);

$y_axis = $y_axis + $row_height;

$i++;

}

 

$pdf->SetFont('Times','B',14);

$pdf->SetXY(100,145);

$pdf->Cell(20,10,'Replaces the following ' . $db_field['Brands'] . ' part numbers:');

$pdf->SetXY(100,156);

$pdf->SetFont('Times','',14);

 

$i=0;

while($i < count($oemcodes)) {

$pdf->SetY($y_axis);

$pdf->SetX(100);

$pdf->MultiCell(150,0,$oemcodes[$i]);

$pdf->Ln(1);

$y_axis = $y_axis + $row_height;

$i++;

}

 

$pdf->Output();

 

echo 'Database Closed, All PDF files have been generated';

mysql_close($db_handle);

}

else {

print "Database NOT Found";

}

 

?>

 

Christian meant "someone, somewhere, just wants to import your data with a single command and be done with it."  There's no reason to export your database to a PDF so human beings can re-type everything into another system.  That's stupid.

 

If they really don't care about the inefficiencies and they insist on a PDF, have PHP spit out the document in HTML with all the tables and whatever, then install a "print to PDF" plugin for your OS.  Everything but windows does it out of the box.

Also as far as them importing.  I have it all in a csv and they will upload it, the issue is that they have a character limit on the description.  Sorry if I wasn't clear about that originally. 

 

Barand I am thinking not. The issue is though that I want two columns side by side and I don't think its actually possible.  I'm thinking I'm going to need to have it show models and then list them out in maybe 3 columns across and then do the part codes.

Multiple columns aren't a great problem. I have regularly produced output like the example below, with 2 or more columns using FPDF.

 

+------------------+-----------------------+

|  Product        |  Codes              |

+------------------+-----------------------+

|  xxxxxxxxxx      |  aaaaa              |

|                  |  bbbb                |

|                  |  ccccccc            |

+------------------+-----------------------+

|  xxxxxxxxxx      |  aaaaa              |

|                  |  bbbb                |

|                  |  ccccccc            |

|                  |  dddd                |

|                  |  eeeeeee            |

+------------------+-----------------------+

|  xxxxxxxxxx      |  aaaaa              |

|                  |  bbbb                |

|                  |  ccccccc            |

+------------------+-----------------------+

Thank you thank you thank you.  This is going to save me a ton of work down the line.  I also apologize for not wrapping the post in code quotes.  I hit post before I could edit and then lost internet for the past hour and a half. 

Maniac Dan,  I was also trying that route but it was seeming to be a little more trouble.  I would need it to loop and for some reason I just was getting stuck.  Anyway I can get this to work i'd love to as I need this done today and I might have to just abandon this for now so that I can just do it manually since I need to have these files completed. 

I had it looping with the pdf and I can probably finish generating the other method of html so that it does loop.  I was just kinda stuck at the issue of getting it to just create the file then save it. I think I barely tried that method since I know the PDF method has to be something simple I am not doing.

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.