dsaxw4201 2015-09-14 03:08
浏览 94
已采纳

如何在mysql中填充数据

usually when i run this query it would always fetch all of the data in the table. but now its just taking a row of the data in the table. Im trying to export the data to Microsoft Wor by using phpword.

how to solve this?

$order_query = mysql_query("SELECT COUNT(id), BuyerName,BuyerEmail,BuyerAddress,TransactionID,ItemAmount,DateTime FROM `order`") 
or die(mysql_error());
$x= 0;
$y= 0;
// Add table
while($row = mysql_fetch_array($order_query))
    {

$x++;
$y++;

// Add table style      
$PHPWord->addTableStyle('myOwnTableStyle."$x".', $styleTable, $styleFirstRow);
$PHPWord->addTableStyle('myOwnTableStyle."$y".', $styleTable, $styleFirstRow);

//create table
$table1 = $section->addTable('myOwnTableStyle."$x".');

// Add row
$table1->addRow(900);  

    $f1 = $row['BuyerName'];
    $f2 = $row['BuyerEmail'];
    $f3 = $row['BuyerAddress'];
    $f4 = $row['TransactionID'];
    $f5 = $row['ItemAmount'];
    $f6 = $row['DateTime'];

// Add cells
$table1->addCell(2000, $styleCell)->addText('Nama', $fontStyle);
$table1->addCell(2000, $styleCell)->addText('Email', $fontStyle);
$table1->addCell(2000, $styleCell)->addText('Alamat', $fontStyle);
$table1->addCell(2000, $styleCell)->addText('ID Transaksi', $fontStyle);
$table1->addCell(2000, $styleCell)->addText('Jumlah', $fontStyle);
$table1->addCell(2000, $styleCell)->addText('Tarikh', $fontStyle);


// Add more rows / cells

    $table1->addRow();
    $table1->addCell(2000)->addText("$f1");
    $table1->addCell(2000)->addText("$f2");
    $table1->addCell(2000)->addText("$f3");
    $table1->addCell(2000)->addText("$f4");
    $table1->addCell(2000)->addText("$f5");
    $table1->addCell(2000)->addText("$f6");



$table = $section->addTable('myOwnTableStyle."$y".');


$table->addRow(900);

$table->addCell(2000, $styleCell)->addText('Nama Barang', $fontStyle);
$table->addCell(2000, $styleCell)->addText('Kod Barang', $fontStyle);
$table->addCell(2000, $styleCell)->addText('Kuantiti Barang', $fontStyle);

//2nd query for details
$detail_query = mysql_query("SELECT * FROM orderlist WHERE TransactionID  = '$f4'");
while($rows = mysql_fetch_array($detail_query))

    {   

    $fd1 = $rows['ItemName'];
    $fd2 = $rows['ItemNumber'];
    $fd3 = $rows['ItemQTY'];

    $table->addRow();
    $table->addCell(2000)->addText("$fd1");
    $table->addCell(2000)->addText("$fd2");
    $table->addCell(2000)->addText("$fd3");



    }
    unset($table);
    unset($table1);

    }
  • 写回答

1条回答 默认 最新

  • dongwei1921 2015-09-14 03:36
    关注

    Just unset $table variable before ending the loop

    while($row=mysql_fetch_array($order_query))
    {
        $x++;
        $table = $section->addTable('myOwnTableStyle'.$x);
    
        ....
    
        unset($table);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿