searls03 Posted April 24, 2011 Share Posted April 24, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/ Share on other sites More sharing options...
Alex Posted April 24, 2011 Share Posted April 24, 2011 In what way isn't it working? Assuming your PDF Output method is supposed to actually output the pdf to the browser, you shouldn't have any other output in your file, so no HTML. Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1205617 Share on other sites More sharing options...
searls03 Posted April 24, 2011 Author Share Posted April 24, 2011 well, I want it to display all names from database, right now it is only displaying my name multiple times! Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1205618 Share on other sites More sharing options...
Alex Posted April 24, 2011 Share Posted April 24, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1205621 Share on other sites More sharing options...
searls03 Posted April 25, 2011 Author Share Posted April 25, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1205697 Share on other sites More sharing options...
searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 anything? Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1207203 Share on other sites More sharing options...
searls03 Posted April 29, 2011 Author Share Posted April 29, 2011 how do I make it beside it? Quote Link to comment https://forums.phpfreaks.com/topic/234597-pdf-help/#findComment-1208283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.