Reputation: 866
I want to select only $limit records from the table with the category $cat.
foreach($cats as $cat) {
$query = $this->createQuery();
$query->matching($query->equals('type', $cat));
$query->setLimit((int)$limit);
$result[] = $query->execute();
}
Is it possible to combine the query result so one query result?
Upvotes: 0
Views: 1355
Reputation: 866
Thank you, I found another way that worked for me:
public function findAllLimitedByCategory($limit, $category){
$cats = explode(",",$category);
$result = array();
foreach($cats as $cat) {
$query = $this->createQuery();
$query->matching($query->equals('type', $cat));
$query->setLimit((int)$limit);
$result[] = $query->execute()->toArray();
}
$out = array();
foreach($result as $r)
$out = array_merge($out, $r);
return $out;
}
...but I have to sort the array by php with this solution
Upvotes: 1
Reputation: 1121
I think your query is something like ,
"SELECT * FROM table_name WHERE type IN ('".$cats."')"
Here $cats is an array of categories like,
$cats = array("cat1", "cat2", "cat3");
Then the extabse query will be,
$query = $this->createQuery();
$query->matching($query->in('type', $cats));
$query->setLimit((int)$limit);
$result = $query->execute();
In the above query in() checks if a single-valued property exists in a multi-value operand.
For more details refer : http://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html
Upvotes: 2