如何在mysql中填充数据 [英] how to populate data in mysql
本文介绍了如何在mysql中填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过使用phpword将数据导出到Microsoft Wor。
如何解决这个问题?
$ order_query = mysql_query(SELECT COUNT(id),BuyerName,BuyerEmail,BuyerAddress,TransactionID,ItemAmount,DateTime FROM`order`)
or die(mysql_error );
$ x = 0;
$ y = 0;
//添加表
while($ row = mysql_fetch_array($ order_query))
{
$ x ++;
$ y ++;
//添加表样式
$ PHPWord-> addTableStyle('myOwnTableStyle。$ x。',$ styleTable,$ styleFirstRow);
$ PHPWord-> addTableStyle('myOwnTableStyle。$ y。',$ styleTable,$ styleFirstRow);
//创建表
$ table1 = $ section-> addTable('myOwnTableStyle。$ x。
//添加行
$ table1-> addRow(900);
$ f1 = $ row ['BuyerName'];
$ f2 = $ row ['BuyerEmail'];
$ f3 = $ row ['BuyerAddress'];
$ f4 = $ row ['TransactionID'];
$ f5 = $ row ['ItemAmount'];
$ f6 = $ row ['DateTime'];
//添加单元格
$ 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);
//添加更多行/单元格
$ 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);
//第二个查询详细信息
$ 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);
}
解决方案
$ table
在结束循环之前的变量
while($ row = mysql_fetch_array ($ order_query))
{
$ x ++;
$ table = $ section-> addTable('myOwnTableStyle'。$ x);
....
unset($ table);
}
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);
}
解决方案
Just unset $table
variable before ending the loop
while($row=mysql_fetch_array($order_query))
{
$x++;
$table = $section->addTable('myOwnTableStyle'.$x);
....
unset($table);
}
这篇关于如何在mysql中填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文