Answer the question
In order to leave comments, you need to log in
MODX COUNT query with a bunch of tables via xpdo?
Hello. I need to determine the number of rows, via count, When I make a direct query from phpmyadmin SELECT fieldname, COUNT(*) FROM table1, table2 WHERE table1.fieldname = table2.fieldname2 GROUP BY table1.fieldname ORDER BY COUNT(*) ASC - everything works fine . displays the result, where it finds a match of values from table 2 in table 1 and makes a list. everything is ok
But how is it from modx? I do this
$c = $modx->newQuery('ClassTable1');
$c->select(array($modx->getSelectColumns('TableClass1', 'TableClass1','',array('fieldname')),$modx->getSelectColumns('TableClass2', 'TableClass2','', array('fieldname2')) ));
$c->select('fieldname, COUNT(*) ');
$c->leftJoin('
$c->groupby('TableClass1.fieldname');
$c->sortby('COUNT(*)','ASC');
- hangs tightly (in the console). if you do not do leftjoin, but do it by analogy with a query in phpmyadmin - only through getSelectColumns and where, it swears that there is no column TableClass2.fieldname2
Answer the question
In order to leave comments, you need to log in
Who's stopping you from doing this?
$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) {
//log exception
}
, where $sql
is your SQL query:$sql = 'SELECT имяполя, COUNT(*) FROM ' . $modx->getTableName('КлассТаблицы1') . ' t1, ' . $modx->getTableName('КлассТаблицы2') . ' t2, WHERE t1.имяполя = t2.имяполя2 GROUP BY t1.имяполя ORDER BY COUNT(*) ASC ';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question