Answer the question
In order to leave comments, you need to log in
How to sort output by numeric value "binary" using xPDO newQuery?
I'm doing a selection of numbers, but sorting like "order by binary value" doesn't work in any way.
What should be added to this code?
$q = $modx->newQuery('modTemplateVarResource');
$q->where(array('tmplvarid' => 17));
$q->select(array('value'));
$q->query['distinct'] = 'DISTINCT';
$q->sortby('value');
$q->prepare();
if($q->stmt && $q->stmt->execute()) $res = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
Answer the question
In order to leave comments, you need to log in
Why don't you do it like this?
<?php
$paramArray = array(
':parent' => 17 //Вот от такой магии лучше тоже избавиться
);
$sql = 'SELECT DISTINCT `x`.value FROM '.$modx->getTableName('modTemplateVarResource').' AS `x`
WHERE `x`.`tmplvarid` = :parent
order by BINARY `x`.`value` ASC';
$query = $modx->prepare($sql);
$modx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try
{
$query->execute($paramArray);
return $query->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e) {
echo 'error occurred! ' . $e->getMessage() . '<br>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question