【发布时间】:2017-05-11 16:14:57
【问题描述】:
我们使用下面的 php 和 javascript 代码来显示表格内的值。
php
function getDesignerCollection(){
$stmts = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmts->execute(array(
":uid" => $_SESSION['userSession']
));
$rows = $stmts->fetch(PDO::FETCH_ASSOC);
$stmt = $user_home->runQuery("SELECT * FROM order_details");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->execute();
$accountType = $rows['type'];
if ($accountType == "admin"){
$is_admin = true;
$order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
'nin' => '0'
));
}
/* Fetching magento db details end */
$i = 0;
foreach($order as $orderData){
$k = 0;
$orderitems = $orderData['dproduct_id'];
$orderitemsarray = explode(",", $orderitems);
while ($k < count($orderitemsarray)){
if ($orderitemsarray[$k] != '0'){
$stmtorders = $user_home->runQuery("SELECT * FROM order_details");
$stmtorders->execute(array(":dorder_id" => $orderData['entity_id']));
$roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);
if($accountType == "admin"){
$designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
while($datas = $stmt1->fetch()){
$paid_status=$datas['dpaid_status'];
$delivery_status=$datas['delivery_status'];
}
$responce[] = array(
$orderData->getIncrementId() ,
$orderitemsarray[$k],
$productdetail->getName() ,
$designerName,
$orderData['status'],
$orderData['grand_total'],
$orderData['customer_email'],
$commission,
$paid_status,
$delivery_status,
$due_date,
$sDate
);
}
$k++;
$i++;
}
return json_encode($responce);
}
脚本
var __TEST_DATA__=eval('<?php
echo getDesignerCollection(); ?>');
var grid_demo_id = "myGrid" ;
var colsOption = [
{id: '' , header: "" , width :"15",renderer : my_renderId , width :"60"},
{id: 'created_at' , header: "Order Date" , width :"100"},
.
.
{id: 'delivery_status' , header: "Delivery Status" , width :"110"},
{id: 'due_date' , header: "Payment Due Date" , width :"140"},
];
现在我在 php 页面中添加了“按钮”,一旦我们点击按钮,它应该以 pdf 格式显示表格。为此,我正在使用 TCPDF 并尝试以下代码。 一旦我单击“按钮”,它就会重定向到 Pdf 页面,但它不显示表中存在的值。
$html = <<<EOD
<h1>Welcome</h1>
EOD;
$html='<table border="0" cellspacing="0" cellpadding="0" style="border:1px solid #e1e1e1">';
$html.='<tr bgcolor="#cccccc" ><th height="20" >Commission</th><th>Paid status</th><th>Delivery date</th><th>Due date</th></tr>';
foreach ($order as $orderData)
{
if(is_array($order[0]))
{
foreach ($order as $orderData)
{
if($i%2==0){ $html.='<tr bgcolor="#d3d6ff">';}else{ $html.='<tr>';}
$html.='<td height="20" > '.$commission.'</td>';
$html.='<td>'.$paid_status.'</td>';
$html.='<td>'.$delivery_status.'</td>';
$html.='<td>'.$due_date.'</td>';
$i++;
$html.='</tr>';
}
}
else
{
if($i%2==0){ $html.='<tr bgcolor="#d3d6ff">';}else{ $html.='<tr>';}
$html.='<td height="20" > '.$commission.'</td>';
$html.='<td>'.$paid_status.'</td>';
$html.='<td>'.$delivery_status.'</td>';
$html.='<td>'.$due_date.'</td>';
$i++;
$html.='</tr>';
}
}
$html.='</table>';
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
完整代码:http://pastebin.com/P5DinusU,我是 php 新手,在这里发布问题之前尝试了很多。
【问题讨论】:
-
$order 中有什么?我认为它是空数组
-
@VijayaVigneshKumar 我们正在从 order_details 表中获取已付款状态、佣金和到期日期的值....请检查完整代码一次:pastebin.com/P5DinusU
-
能否请您 print_r($order);并将结果粘贴到此处
-
意思是我需要那个数组
-
我有一个疑问,请您澄清一下
标签: javascript php pdf tcpdf