I fought this thing until late last night and the script has now changed to this:
<?php
if(isset($_POST['submit'])){
$EmployeeID=$_SESSION['eid'];
$connection = new mysqli($h['DOST'],$u['DOST'],$p['DOST'],$d['DOST']);
$connection->select_db($d['DOST']);
$fp = fopen('uploads/AMZListings.csv', 'wt');
$filename = "AMZListings.csv";
$sql = "SELECT SubmissionID, ASIN, MinBid, SubxText, ItemCondition, SubxTitle ";
$sql .="FROM tblSubmissions ";
$sql .="WHERE Ready='YES'";
$result = $connection->query($sql) or die (mysql_error());
$SUB_Count=$result->num_rows;
if($SUB_Count>0){
$i=0;
while($row=$result->fetch_row()){
$SubmissionID[$i]=$row[0];
$ASIN[$i]=$row[1];
$MinBid[$i]=$row[2];
$SubxText[$i]=$row[3];
$ItemCondition[$i]=$row[4];
$SubxTitle[$i]=$row[5];
$list[$i] = array($SubmissionID[$i],$ASIN[$i],'1',$MinBid[$i],$ItemCondition[$i],'1','a','1','',$SubxText[$i],'');
$i++;
}
$result->free();
foreach($list as $newlist){
fputcsv($fp, $newlist, "\t");
}
for($i=0; $i<=$SUB_Count-1; $i++){
//if($result->num_rows>0){
//$Aucsql = "INSERT INTO tblListings";
//$Aucsql .= "(SubmissionID, AuctionSiteID, AuctionTitle, MinBidPrice, DateStarted, DateEnded, AuctionNumber, LastModifiedBy, LastModifiedTS, Quantity) ";
//$Aucsql .= "VALUES('$SubmissionID[$i]', 'AMZ', '$SubxTitle[$i]', '$MinBid[$i]', NOW(), '0000-00-00', '$SubmissionID[$i]', '$EmployeeID', NOW(), '1')";
//$connection->query($Aucsql);
//$SubUpdate = "UPDATE tblSubmissions set Ready=' ' WHERE SubmissionID='$SubmissionID[$i]'";
//$connection->query($SubUpdate);
}
//}
echo "Export done";
}
else{
echo "Nothing to Export";
}
fclose($fp);
$connection->close();
}
else{
print "<form action='csvamzdownload.php' method='post'>";
print "Just click Submit<br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
I set this up for testing purposes, hence the reason why the lower half is commented out.
What this gives me is a file that has all the information that is needed, I can open the file with a text editor or a browser and it outputs what looks to be a tab delimited. However when I open it with an calc/excel program I get the first 5 results in the first column and the last 2 are two rows down, there is also only 1 row from the query that got returned.
When I change the script to look like this:
while($row=$result->fetch_row()){
$SubmissionID[$i]=$row[0];
$ASIN[$i]=$row[1];
$MinBid[$i]=$row[2];
$SubxText[$i]=$row[3];
$ItemCondition[$i]=$row[4];
$SubxTitle[$i]=$row[5];
$list = array();
$list[$i] = array($SubmissionID[$i],$ASIN[$i],'1',$MinBid[$i],$ItemCondition[$i],'1','a','1','',$SubxText[$i],'');
$i++;
}
$result->free();
foreach($list as $newlist){
fputcsv($fp, $newlist, "\t");
}
I get one row of the query returned however it is right and I can open it with a calc/excel program.
There is something that I am missing I just can't seem to see it.
Any help is appreciated.
Thanks
FNP