在底部是我的代码。我有8列sku,价格1,价格2,价格3,最低价格,数量1,数量2,数量3数据库
我想在脚本中添加一些if语句来检查三个参数。如果数量>0
目前,我出口的价格从1-3最低的数字,但它没有检查是否有任何数量超过0。
这是我的密码:
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die(':)');
}
echo "Cron is running";
$hostname = 'localhost';
$username = 'user';
$password = 'pass';
$myDatabase = 'database';
/**
* Defines the name of the table where data is to be inserted
*/
$table = 'mytable';
try {
$conn = new PDO('mysql:host=localhost;dbname='.$myDatabase, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT mytable.SKU AS SKU, LEAST(price, price2, price3) AS 'Lowest2'
FROM mytable
");
$stmt->execute();
$filelocation = 'assets/exports/';
$filename = 'export-'.date('Y-m-d H.i.s').'.csv';
$file_export = $filelocation . $filename;
$data = fopen($file_export, 'w');
$csv_fields = array();
$csv_fields[] = 'SKU';
$csv_fields[] = 'Lowest2';
fputcsv($data, $csv_fields);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
fputcsv($data, $row);
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
1条答案
按热度按时间guicsvcw1#
您可以将查询更改为:
我假设所有的价格都低于999999999。。。