我想选择并编写特定的列名,因为我想如何做到这一点? 情况是:
$stockQuery = mysql_query("SELECT stokId,urunAdi,tlFiyat,stokMiktari,tlFiyat*stokMiktari,urunGrup,maliyetTipi FROM proje_stok where projeID =".$projeID);
但我确实想选择
select * from proje_stok where ......
我当前的编写代码是
while($row_data = mysql_fetch_assoc($stockQuery)) {
$col = 0;
if ($col == 0) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $order);
$col++;
}
foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col++;
}
$row++;
$order++;
}
而不是我想使用像
这样的代码foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['HEREWHATIWANTTOPUTCOLUMNNAME']);
$col++;
}
有什么建议要处理吗?
问候
答案 0 :(得分:1)
$col = $row = $order = 1;
if ($row_data = mysql_fetch_assoc($stockQuery))
{
foreach ($row_data as $key => $value)
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(++$col, $row, $key);
do
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col = 1, ++$row, $order++);
foreach ($row_data as $value)
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(++$col, $row, $value);
}
while ($row_data = mysql_fetch_assoc($stockQuery));
}