$total = $my_xpdo->getCount();
$query = $my_xpdo->newQuery('Vendors');
$query->where(array(
'name:LIKE' => "%$search_term%",
'OR:city:LIKE' => "%$search_term%"
)
);
$query->andCondition(array('is_published' => '1') ); # Little safety valve@param mixed $criteria Any valid xPDOCriteria object or expression.
count($resultingArray);
You are doing a GROUP BY model, so it looks like you want to select("COUNT(DISTINCT model)") here (don’t select id OR your sum() expression, or add the group by until you are actually getting the rows because grouping by model is the same as returning a single row per model); you’ll have to find the proper COUNT() expression to match the rows you are returning in the actual query, i.e.:
<?php
//Retreive the count
$c = $modx->newQuery($table);
$c->select("COUNT(DISTINCT model)");
if ($c->prepare() && $c->stmt->execute()) {
$rows = $c->stmt->fetchAll(PDO::FETCH_COLUMN);
$count = (integer) reset($rows);
//Do the actual query only if there is a count
if ($count > 0) {
$c = $modx->newQuery($table);
$c->select('id, model, SUM(failures) as failures');
$c->groupBy('model');
$c->sortby($sort,$dir);
$c->limit($limit, $start);
$fields = $modx->getCollection($table, $c);
}
}$count= 0;
if($c->prepare() && $c->stmt->execute()){
$count= $c->stmt->rowCount();
}