gpt4 book ai didi

php - 数组未以 pdf 格式显示在新窗口中。使用 fpdf 类

转载 作者:行者123 更新时间:2023-11-30 22:38:02 25 4
gpt4 key购买 nike

    while ($row = mysql_fetch_assoc($result)) {
$_SESSION['arr1'] = $row;
$_SESSION['arr2'][] = $_SESSION['arr1'];
$_SESSION['data'][] = $row['awb_no'];
$_SESSION['items'] = $_SESSION['data'];
}
echo"The new value has been scanned!</br>";
echo "<hr>";
echo "The tracking id's of the currently scanned items are given below<br><hr>";
foreach ($_SESSION['items'] as $x => $value)
{
echo "$value";
echo "<br>";
# code...
}

echo "<br><hr>";
print_r($_SESSION['arr2']);
echo "<hr>";
print_r($_SESSION['items']);
echo "<a href='something.php'>download in pdf format</a>";
}
}
else
{
session_destroy();
}
?>
</body>
</html>

以上代码是整个php文件的一部分。简而言之,这个 php 文件包含一个以下列方式存储数据的数组,

Array ( [0] => Array ( [d_no] => 21312 [a_no] => 05153341 [order_id] => 9929633865300 [forms] => [extras] => [flag] => 2015-08-07 14:18:04.0000 ) )  

我希望将上述数组传递给另一个页面,该页面读取该数组并使用 fpdf 类显示它。该页面的代码如下所示,

<?php
session_start();
?>
<?php
$host="localhost";
$user="root";
$password="";
$db="greenmobiles";
mysql_connect("$host","$user","$password") or die("Cannot Connect");
mysql_select_db("$db") or die("Cannot select DB!");
require_once( "fpdf/fpdf.php" );
$textColour = array( 0, 0, 0 );
$headerColour = array( 100, 100, 100 );
$tableHeaderTopTextColour = array( 255, 255, 255 );
$tableHeaderTopFillColour = array( 125, 152, 179 );
$tableHeaderTopProductTextColour = array( 0, 0, 0 );
$tableHeaderTopProductFillColour = array( 143, 173, 204 );
$tableHeaderLeftTextColour = array( 99, 42, 57 );
$tableHeaderLeftFillColour = array( 184, 207, 229 );
$tableBorderColour = array( 50, 50, 50 );
$tableRowFillColour = array( 213, 170, 170 );
$columnLabels = array( "Sl No.", "Tracking id", "Forms req", "Extras" );
$data = $_SESSION['arr2'][];

// End configuration


/**
Create the title page
**/

$pdf = new FPDF( 'P', 'mm', 'A4' );
$pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
$pdf->AddPage();


/**
Create the table
**/

$pdf->SetDrawColor( $tableBorderColour[0], $tableBorderColour[1], $tableBorderColour[2] );
$pdf->Ln(15);

// Create the table header row
$pdf->SetFont( 'Arial', 'B', 15 );
// Remaining header cells
$pdf->SetTextColor( $tableHeaderTopTextColour[0], $tableHeaderTopTextColour[1], $tableHeaderTopTextColour[2] );
$pdf->SetFillColor( $tableHeaderTopFillColour[0], $tableHeaderTopFillColour[1], $tableHeaderTopFillColour[2] );

for ( $i=0; $i<count($columnLabels); $i++ ) {
$pdf->Cell( 36, 12, $columnLabels[$i], 1, 0, 'C', true );
}

$pdf->Ln( 12 );

// Create the table data rows

$fill = false;
$row = 0;

foreach ( $data as $dataRow ) {

// Create the left header cell

// Create the data cells
$pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
$pdf->SetFillColor( $tableRowFillColour[0], $tableRowFillColour[1], $tableRowFillColour[2] );
$pdf->SetFont( 'Arial', '', 15 );

for ( $i=0; $i<count($columnLabels); $i++ ) {
$pdf->Cell( 36, 12, ( '$' . number_format( $dataRow[$i] ) ), 1, 0, 'C', $fill );
}

$row++;
$fill = !$fill;
$pdf->Ln( 12 );
}



$pdf->Output( "report.pdf", "I" );
?>

我希望传递到此页面的数组条目以 pdf 格式的表格形式显示,以便可以下载。

以下是我遇到的错误,

Notice: Undefined offset: 0 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 1 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 2 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 3 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 0 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 1 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 2 in E:\XAMPP\htdocs\xampp\something.php on line 71

Notice: Undefined offset: 3 in E:\XAMPP\htdocs\xampp\something.php on line 71 FPDF error: Some data has already been output, can't send PDF file

最佳答案

出现是因为数组元素不存在。所以像这样验证。

 //check for existence
if(isset($dataRow)) {
$pdf->Cell( 36, 12, ( '$' . number_format( $dataRow['d_no'] ) ), 1, 0, 'C', $fill );
$pdf->Cell(10);
$pdf->Cell( 36, 12, ( '$' . number_format( $dataRow['a_no'] ) ), 1, 0, 'C', $fill );
$pdf->Cell(10);
$pdf->Cell( 36, 12, ( '$' . number_format( $dataRow['order_id'] ) ), 1, 0, 'C', $fill );
------
.....
.....
---------
}

最后一个错误是由于之前的通知列表。清除后,FPDF 输出错误将清除。

关于php - 数组未以 pdf 格式显示在新窗口中。使用 fpdf 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31878709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com