$stmt = ("SELECT FROM_UNIXTIME(`stock`.`created_at`, '%Y-%m-%d') as date,stock.pid,stock.name,stock.description,stock.price,stock.final_price as cost, FROM `stock` WHERE stock.type = 'partbike' AND stock.store = 'TWN'");
$query = mysqli_query($db,$stmt);
// // Fetch records from database
// $query = $db->query(");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "stock" . date('Y-m-d') . ".csv";
// Create a file pointer
$f = fopen('php://memory', 'w');
// Set column headers
$fields = array('Date','Part.ID','Make','Model','Price','Cost');
fputcsv($f, $fields, $delimiter);
// Output each row of the data, format line as csv and write to file pointer
while($row = $query->fetch_assoc()){
// $status = ($row['status'] == 1)?'Active':'Inactive';
$lineData = array($row['date'], $row['pid'], $row['name'], $row['description'], $row['price'], $row['cost']);
fputcsv($f, $lineData, $delimiter);
}
The if statement is meant to check if the number of data collected if above zero to avoid errors of null values in the future. Anyone with an idea why am getting that error?