问题描述
当所有输入值均为空(价格除外)时,我正在尝试从输入值获取数据。它没有回声。如果所有值都为空,我也会做方法,它会回显所有产品。很好。
首先,我解码JSON文件并检查所有产品。当价格低于我给输入值的限制时,它将这些产品推向新的数组。循环和新数组后,我将其编码回JSON。这个循环工作正常,我尝试了链接。现在,我正在执行index.PHP,您可以在其中提供自定义限制。它不起作用。
问题出在哪里?它以某种方式认为所有值都是空的,因为它回显了所有乘积。
我也尝试过SELECT s.*,MAX(CASE WHEN t.id IS NULL THEN 'no' ELSE 'yes' END) eit
FROM sales s
LEFT
JOIN tranches t
ON t.campaign = s.campaign
GROUP
BY s.id
,但也没有工作。
!empty
<?PHP
$nimi = $_POST["nimi"];
$kategoria = $_POST["kategoria"];
$paino = $_POST["paino"];
$tuoteid = $_POST["tuoteid"];
$hinta = $_POST["hinta"];
$tavarat_json = file_get_contents('tuotteet.json');
$tavarat_array = json_decode($tavarat_json); // To Array
// If all inputs are empty,echo all products -> WORKS FINE
if( empty($_GET[$hinta]) and empty($_GET[$kategoria]) and empty($_GET[$paino]) and empty($_GET[$tuoteid]) and empty($_GET[$nimi]) ) {
header("Content-Type: application/json; charset=UTF-8"); // browser understand this is JSON and parse it nicely
echo $tavarat_json;
}
// If all inputs are empty except price
if( isset($_GET[$hinta]) and empty($_GET[$kategoria]) and empty($_GET[$paino]) and empty($_GET[$tuoteid]) and empty($_GET[$nimi]) ) {
header("Content-Type: application/json; charset=UTF-8"); // browser understand this is JSON and parse it nicely
$uudet_tuotteet = array();
foreach ($tavarat_array as $tavara) {
if ($tavara->hinta < ($_GET[$hinta]) ) { // Where hinta is lower than gave in input
array_push($uudet_tuotteet,$tavara); // Push to empty array
}
}
if(count($uudet_tuotteet) == 0) { // If amount of product is zero,echo "No products"
echo json_encode("Tuotetta ei löydy"); // To JSON
}
else {
$uudet_tuotteet_json = json_encode($uudet_tuotteet); // To JSON
echo $uudet_tuotteet_json;
}
}
?>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)