0
我已经创建了这个php脚本来从我的数据库中提取一些数据并将其导出为CSV。SQL,PHP导出为CSV静态字段
我有设定为0,1,2,3,4,5头,但我需要在4列2,3,一些静态文字和5
如股票代码,数量,静态的,静态,静态,静态。
股票代码,数量正在从数据库中提取。
任何帮助,将不胜感激。
我的代码如下。
// open connection to mysql database
$connection = mysqli_connect($host, $username, $password, $dbname) or die("Connection Error " . mysqli_error($connection));
// fetch mysql table rows
$sql = "select ManufacturerPartNumber, (QuantityOnHand - QuantityOnSalesOrder) from iteminventory";
$result = mysqli_query($connection, $sql) or die("Selection Error " . mysqli_error($connection));
$fp = fopen('inventory.csv', 'w');
fputcsv($fp, array('0', '1', '2', '3' '4' '5'));
while($row = mysqli_fetch_assoc($result))
{
fputcsv($fp, $row);
}
fclose($fp);
//close the db connection
mysqli_close($connection);
我用这个代码,一天拉东西放到第一列。
$id = 0; // or whatever else you want to have in the first column while($row = mysqli_fetch_assoc($result))
{
array_unshift($row, $id);
fputcsv($fp, $row);
$id; }