我需要在ASC订单中按ORDER BY number
字段,但它无效。
$sThree = "SELECT `id`, `name`, `number`, `logo` FROM `itv` WHERE `id` = {$rTwoArray['service_id']} ORDER BY `number` ASC";
$qThree = mysql_query($sThree, $conn1);
$rThree[] = mysql_fetch_assoc($qThree);
无法弄清楚,请帮我调试。
答案 0 :(得分:1)
上面显示的查询不同,结果图像也不同。您已使用WHERE id = {something}
它应该在结果中提供所有相同的id
。请附上正确的结果。
您在此处获得的查询结果可能来自另一个查询,这就是您无法获得有序结果的原因。
每当代码行为不自然时,首先要看代码是在循环中工作还是从不假设。
答案 1 :(得分:0)
使用MySQL CAST(expression AS TYPE)
order by CAST(number AS SIGNED) ASC
尝试此MySQL查询
$sThree = "SELECT `id`, `name`, `number`, `logo` FROM `itv`
WHERE `id` = {$rTwoArray['service_id']} order by CAST(number AS SIGNED) ASC";
答案 2 :(得分:0)
由于查询是在循环中,我对最终数组进行了排序。
$sThree = "SELECT `id`, `name`, `number`, `logo` FROM `itv` WHERE `id` = {$rTwoArray['service_id']}";
$qThree = mysql_query($sThree, $conn1);
$rThree[] = mysql_fetch_assoc($qThree);
usort($rThree, function ($item1, $item2) {
return $item1['number'] >= $item2['number'];
});
debug($rThree);