我正在尝试在php中使用数字格式变量来按顺序排序mysql中的函数。我是mysql编码的新手,变量适用于我拥有的另一组php代码。有人可以帮我弄清楚为什么变量不能正确排序。
<?php $price = number_format ($info['Price']/9,2);
$order = mysqli_query($con, "
SELECT DivisionOf, Manufacturer, Collection, Style, Price, ShowPrice, Include, Fiber, Width, Backing
...
GROUP BY ProductID
ORDER BY
CASE WHEN ((Price <= '0.00') OR (Price >= '50.00') OR (ShowPrice!='Yes'))
THEN Style ELSE 0 END asc,
CASE WHEN (Price > '0.00') AND (Price < '50.00') AND (ShowPrice='Yes')
THEN $price ELSE 0 END asc,
CASE WHEN (Price > '0.00') AND (Price < '50.00') AND (ShowPrice='Yes')
THEN Style ELSE Manufacturer END asc,
CASE WHEN (Price > '0.00') AND (Price < '50.00') AND (ShowPrice='Yes')
THEN Manufacturer END asc;
");
// Gather data from database
mysqli_data_seek($order, 0);
while($info = mysqli_fetch_array( $order ))
include($_SERVER['DOCUMENT_ROOT'].$info['Include']);?>
答案 0 :(得分:0)
我只是将代码中的变量更改为格式而不是使用变量,而是使用了变量。即。
CASE WHEN (Price > '0.00') AND (Price < '50.00') AND (ShowPrice='Yes')
THEN $price ELSE 0 END asc,
到
CASE WHEN (Price > '0.00') AND (Price < '50.00') AND (ShowPrice='Yes')
THEN FORMAT (Price/9,2) ELSE 0 END asc,