English 中文(简体)
PHP Excel写Excel和服务器节省费用?
原标题:PHPExcel write Excel and save to the server?

www.un.org/Depts/DGACM/index_spanish.htm 现行法典:

<?php

  /** PHPExcel */
  require_once  ../Classes/PHPExcel.php ;

  /** PHPExcel_IOFactory */
  require_once  ../Classes/PHPExcel/IOFactory.php ;

  // Create new PHPExcel object
  $objPHPExcel = new PHPExcel();

  // Set properties
  $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                               ->setLastModifiedBy("Maarten Balliauw")
                               ->setTitle("Office 2007 XLSX Test Document")
                               ->setSubject("Office 2007 XLSX Test Document")
                               ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                               ->setKeywords("office 2007 openxml php")
                               ->setCategory("Test result file");

  $result =  select * from table1 ;

  for($i=0;$i<count($result);$i++) {

    $result1 =  select * from table2 where table1_id =   . $result[$i][ table1_id ];

    for ($j=0;$j<count($result1);$j++) {
      $objPHPExcel->setActiveSheetIndex(0)->setCellValue( A  . $j, $result1[$j][ name ]);
    }

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    // Save Excel 2007 file
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,  Excel2007 );
    $objWriter->save(str_replace( .php ,  .xlsx , __FILE__));

    // Echo done
    echo date( H:i:s ) . " Done writing file.
";       
  }

?>

以上代码在纸浆中执行并保存无<代码>xlsx文档,但问题Im 插入是最大的<代码>count(result1),载于。

最佳回答

在深入讨论之前,一件事情是显而易见的。

您的 t用了电梯,既未提电费,也未用你无法使用的电灯费支付。

存在Same问题,费用为1美元

您可以使用:

$result = mysql_query( select * from table1 );
while($fetch_result=mysql_fetch_array($result))
{
    $result2 = mysql("select * from table2 where table1_id =  ".$fetch_result[ table1_id ]." ");

   while($fetch_result2=mysql_fetch_array($result2)
   {
    --your code--

但最好是写JOIN,而不是这两个问题。

问题回答

您将希望mysql_num_rows - rel=“nofollow noreferer”>。 http://php.net/manual/en/Function.mysql-num-rows.php

$q =  select * from table1 ;
$res = mysql_query($q);
$count = mysql_num_rows($result);

for ($j=0;$j<$count;$j++) {
    #code here
}

页: 1





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签