I'm trying to output/write mysql SELECT results to a text file. The SELECT statement results are three records but when i use fwrite to write these results to a textfile, only one record is written. What can i be possibly be doing wrong? Here is the code snippet
<?php
include "data.php";
$con=dbConnect();
$query="select * from manuscript where month(pubcom_submission_date) = month(now()) order by manuscript_id desc";
$sql=$con->prepare($query);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $sql->fetch()){
$list[]= $row['authors'] .','.$row['title'].','.$row['year'].','.$row['journal'];
}//print_r($list);
foreach($list as $line){
echo "$line<p>";
print_r($line);
//echo "here";
}
$myfile = "/home/alex/Documents/biblio.txt";
$handle = fopen($myfile, 'w') or die('cannot open file: '.$myfile);
$data = $line;
fwrite($handle, $data);
?>