我怎样才能从一个MySQL数据库创build一个PHP数据数组作为PHPReport Maker中的input

我正在尝试使用PHPReport创build一个可导出到Excel和PDF的PHP 报表 。 我已经testing了报告插件,并且已经能够创build一个合适的模板来适合我想要的报告。 然而,我很难搞清楚如何使用mysql查询中的结果集作为input参数来生成报告。

报告插件只给出了一个使用数组数组的input数据的例子,如下所示。

$products=array( array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>2, 'narrative'=>'Yes'), array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>2, 'narrative'=>'Yes'), array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>2, 'narrative'=>'Yes'), array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>1122, 'narrative'=>'Yes'), array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>6, 'narrative'=>'Yes'), array('transdate'=>'Example product','ref'=>2,'debit'=>4.5,'credit'=>9, 'bal'=>5, 'narrative'=>'Yes') ); 

如何使用Mysql查询中的结果集作为input数据?

以下是报告生成脚本的示例

 <?php include '../PHPReport.php'; //which template to use if(isset($_GET['template'])) $template=$_GET['template']; else $template='invoice.xls'; //set absolute path to directory with template files $templateDir='C:\wamp\www\ph\PHPReport\examples\template\\'; //we get some products, eg from database $products=array( array('description'=>'Example product','qty'=>2,'price'=>4.5,'total'=>9), array('description'=>'Another product','qty'=>1,'price'=>13.9,'total'=>13.9), array('description'=>'Super product!','qty'=>3,'price'=>1.5,'total'=>4.5), array('description'=>'Yet another great product','qty'=>2,'price'=>10.8,'total'=>21.6), array('description'=>'Awesome','qty'=>1,'price'=>19.9,'total'=>19.9) ); //set config for report $config=array( 'template'=>$template, 'templateDir'=>$templateDir ); $R=new PHPReport($config); $R->load(array( array( 'id'=>'inv', 'data'=>array( 'date'=>date('Ym-d'), 'number'=>312, 'customerid'=>12, 'orderid'=>517, 'company'=>'Example Inc.', 'address'=>'Some address', 'city'=>'Some City, 1122', 'phone'=>'+111222333' ), 'format'=>array( 'date'=>array('datetime'=>'d/m/Y') ) ), array( 'id'=>'prod', 'repeat'=>true, 'data'=>$products, 'minRows'=>2, 'format'=>array( 'price'=>array('number'=>array('prefix'=>'$','decimals'=>2)), 'total'=>array('number'=>array('prefix'=>'$','decimals'=>2)) ) ), array( 'id'=>'total', 'data'=>array('price'=>68.9), 'format'=>array( 'price'=>array('number'=>array('prefix'=>'$','decimals'=>2)) ) ) ) ); echo $R->render('excel'); exit();