-1

我试图找出 xPDO SQL 查询的排序顺序有什么问题,

这个查询

$criteria = $this->modx->newQuery($table);
$criteria->sortby($sortby,$sortdir);
$options = $this->modx->getCollectionGraph($table,$criteria);
$criteria->prepare();
echo '<pre>'.$criteria->toSQL().'</pre>';

导致这个 SQL ~ 这是正确的:

SELECT `Location`.`id` AS `Location_id`, `Location`.`created` AS `Location_created`,
 `Location`.`modified` AS `Location_modified`, `Location`.`location` AS 
`Location_location`, `Location`.`group` AS `Location_group`, `Location`.`comment` 
AS `Location_comment` 
FROM `flow_location` AS `Location` ORDER BY location asc

但是,如果我尝试循环查询:

foreach($options as $option) {
    echo $option->get($value).'<br>';
}

它将通过数据库中的订单ID显示记录!?

我该如何解决?

4

1 回答 1

1

您按 订购location asc,但未location在您的查询中定义。您将列重命名locationLocation_location,因此您应该按Location_location asc.

SELECT `Location`.`id` AS `Location_id`, `Location`.`created` AS `Location_created`,
 `Location`.`modified` AS `Location_modified`, `Location`.`location` AS 
`Location_location`, `Location`.`group` AS `Location_group`, `Location`.`comment` 
AS `Location_comment` 
FROM `flow_location` AS `Location` ORDER BY location asc
于 2014-03-25T01:08:38.170 回答