Jump to content

pdf help


searls03

Recommended Posts

how do I make a pdf that will display all results from a table or selected results, such as all names.  ..........here is one that i started on but isn't working.......

 

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members");
while($row = mysql_fetch_array($sql)){
$name = $row['name'][$key];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
}

$name1 =
$select = mysql_query("SELECT * FROM members") or die(mysql_error());
    while ($member = mysql_fetch_array($select)) {
         ''.$member[name].'';
    }
    

    




require('fpdf.php');

class PDF extends FPDF
{
//Page header
function Header()
{
global $name1;
    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(30,10,'',1,0,'C');
    //Line break
    $this->Ln(20);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',;
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10, $name ,0,1);
$pdf->Output();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

Link to comment
Share on other sites

Instead of this:

 

$name1 =
$select = mysql_query("SELECT * FROM members") or die(mysql_error());
    while ($member = mysql_fetch_array($select)) {
         ''.$member[name].'';
    }
    

and this:

$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10, $name ,0,1);
$pdf->Output();

 

Which I'm not very sure what you're trying to accomplish with it.. You should loop through the database list and add them to the PDF at the same time, in a single loop. So something like this:

 

$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$select = mysql_query("SELECT * FROM members") or die(mysql_error());
while($member = mysql_fetch_array($select)) {
    $pdf->Cell(0,10, $member['name'] ,0,1);
}
$pdf->Output();

Link to comment
Share on other sites

ok, so I put it in a different place and now I need it to display $member[rank] in a cell next to the name...........I can only manage to make it under the name.........how can I do this?

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT name FROM members");
while($row = mysql_fetch_array($sql)){
$name = $row['name'];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
}

    

    




require('fpdf.php');

class PDF extends FPDF
{
//Page header
function Header()
{

    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(30,10,'',1,0,'C');
$this->Ln(20);
   $select = mysql_query("SELECT * FROM members") or die(mysql_error());
while($member = mysql_fetch_array($select)) {
    $this->Cell(50,10,"$member[name]",1,1);
$this->Cell(50, 10, "$member[rank]", 1,1);}

    //Line break
    $this->Ln(20);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',;
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$pdf->Output();
?>

Link to comment
Share on other sites

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.