如何在fpdf中打印出来自mysql的多行

时间:2015-05-27 03:31:40

标签: php mysqli printing fpdf

有人可以帮我解决这个问题吗?

我正在尝试从表格中打印出多种成分 对于fpdf所以我可以将其保存为pdf,但出于某种原因,当我输出 列,它只打印最后一项。  这是我的代码:

<?php
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('display_errors', 'On');
// Start the session
session_start();
if(!isset($_SESSION['userid']) && empty($_SESSION['userid'])) {
  header( 'Location: indexwlogin.php' ) ;
}
?>
<?php
$listitems = $_REQUEST['id'];
//MySQL Database Connect 
//select ingredients.ingredient from grocery inner join ingredients on grocery.ingredients_id = ingredients.id where ingredients.recipeing_id ='1'
include 'dbconnect.php';
$sqlstatement4 = "select grocery.id, recipes.name from grocery inner join ingredients on grocery.ingredients_id = ingredients.id inner join recipes on ingredients.recipeingd_id = recipes.id where grocery.user_id ='".$_SESSION['userid']."'";
    $sql_result4 = mysqli_query($connection, $sqlstatement4) or die(mysqli_error($connection));
    while ($row = mysqli_fetch_array($sql_result4)) 
     { 
         $groceryid = $row["id"];
         $ingname = $row["name"];
     }

$sqlstatement3 = "select ingredients.ingredient from grocery inner join ingredients on grocery.ingredients_id = ingredients.id where ingredients.recipeingd_id ='".$listitems."'";
    $sql_result3 = mysqli_query($connection, $sqlstatement3) or die(mysqli_error($connection));
    while ($row = mysqli_fetch_array($sql_result3)) 
     { 
         $ings = $row["ingredient"];

     }


require("fpdf17/fpdf.php");

$grocerylist = new FPDF();
$grocerylist->AddPage();
$grocerylist->SetFont("Arial","B","20");
$grocerylist->Cell(0,10,"Grocery List for $ingname",1,1,"C");

$grocerylist->SetFont("Arial","I","20");
$grocerylist->Cell(50,40,"$ings",1,1,"C");
 //$grocerylist->Cell(50,40, $ings,1,1,'C');
$grocerylist->Output();

?>

1 个答案:

答案 0 :(得分:0)

while($row=mysqli_fetch_array($sql_result3)){ $grocerylist->Cell(50,40,$row['ingredient']); $grocerylist->Ln(); }

嗨,使用这种方式使用foreach或while.And如果这也不起作用 var_dump($sql_result3)检查您获得的记录数和记录数。