次のコード出力CSVファイルにSQLクエリ結果:phpからcsvの1行にsqlクエリの結果を挿入するには?
1:
CODE
<?php
// Report all errors except E_NOTICE
error_reporting(E_ALL^E_NOTICE);
//connection file
include("connection.php");
$query = 'SELECT resting_blood_sugar,serum_cholesterol,thalach,oldpeak,result,date from hd_test WHERE patient_id = 2';
$output = fopen('N:\oldpatientgraph.csv', 'w');
$result = mysqli_query($link,$query);
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($result)) fputcsv($output, $row);
?>
OUTPUT
CSVファイルは次の形式で出力を含んでいます、1,1,1,1,11-1-2015#line1
2,3,1,4,2,1-1-2000#1 LINE2
次のように私は出力に1行に結果を望むのに対し:
1,1,1,1,1、 11-1-2015,2,3,1,4,2,1-1-2000#line1
誰でもこれを行う方法を知っていますか?
'$ out = []; while($ row = mysqli_fetch_assoc($ result))$ out = array_merge($ out、array_values($ row));; fputcsv($ output、$ out); ' – splash58
それは@ splash58を動かしました。 ありがとう助けをたくさん:) – Neha