AddPage(); // We define the title of this document $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'My Catalog!',1,1); // Init Database related information /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'macmanu_webprog'; /*** mysql password ***/ $password = 'D9wUbZN2uk'; $dbname = 'macmanu_example'; try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); /*** set the error reporting attribute ***/ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*** SQL Query ***/ $query = "select article.name as name, article.price as price, ". "category.name as category, article.articleID ". "from article, category ". "where article.categoryID=category.categoryID"; /*** loop of the results ***/ $stmt = $dbh->query($query); while( $obj = $stmt->fetch(PDO::FETCH_OBJ)){ $links[$obj->articleID]=$pdf->AddLink(); $pdf->SetFont('Arial','B',12); $pdf->Write(5, "$obj->name, ",$links[$obj->articleID]); $pdf->SetFont('Arial','I',12); $pdf->Write(5, $obj->category); $pdf->ln(5); $articles[]=$obj; } $i=0; // For each article, we write a page foreach($articles as $art){ if($i%2 == 0){ $pdf->addPage(); } else{ $pdf->setY(130); } $i++; $pdf->SetLink($links[$art->articleID]); $pdf->SetFont('Arial','B',26); $width = $pdf->GetStringWidth($art->name)+6; $pdf->SetX(35); $pdf->Cell($width,10, $art->name,1); $pdf->ln(20); $pdf->SetFont('Arial','I',15); $pdf->Cell(50,5, "CHF ".$art->price); //$pdf->Cell(30); $pdf->Cell(50,5, $art->category); $pdf->ln(); $pdf->SetFont('Arial','B',10); $pdf->MultiCell(170,5,$art->description); } /*** close the database connection ***/ $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } $pdf->Output(); ?>