[英]TYPO3 create query
I am trying to create a simple query using TYPO3 . 我正在尝试使用TYPO3创建一个简单的查询。 I'm trying to retrieve all results from a table where the name starts with a numerical value , then sort them. 我正在尝试从名称以数字值开头的表中检索所有结果,然后对它们进行排序。 Unfortunately creating a $statement variable doesn't work. 不幸的是,创建$ statement变量不起作用。 How can I do this using the TYPO3 type of queries ( $query->matching
, $query->like
). 如何使用TYPO3类型的查询( $query->matching
, $query->like
)执行此操作。 Thank you for your answer. 谢谢您的回答。
UPDATE: 更新:
TYPO3 Version : 8.7.3 TYPO3版本:8.7.3
What I tried : 我试过了
public function sortReferencesNumerically(){
$query = $this->createQuery();
$statement = 'select * from tx_referencemanager_domain_model_reference WHERE name REGEXP '^[0-9]' ORDER BY CAST(name as SIGNED INTEGER) ASC';
$query->statement($statement);
return $query->execute();
}
NewUpdate : Unfortunately i can't use the $statement method , even tough it works. NewUpdate:不幸的是,我无法使用$ statement方法,即使它很难工作。 Is there anyway to do this without the query->statement method ? 无论如何,如果没有query-> statement方法,这样做吗? I tried this , but it only shows the first data in the table that starts with a numerical character, even tough I have like 20-30. 我尝试过此方法,但它只显示表格中以数字字符开头的第一个数据,即使我喜欢20-30,也很难。
array_push($queryConstraints, $query->logicalOr([
$query->like('name', '0%'),
$query->like('name', '1%'),
$query->like('name', '2%'),
$query->like('name', '3%'),
$query->like('name', '4%'),
$query->like('name', '5%'),
$query->like('name', '6%'),
$query->like('name', '7%'),
$query->like('name', '8%'),
$query->like('name', '9%'),
]));
Your string is broken. 你的绳子坏了。 If you encapsulate a string in single quotes, dont use single quotes to delimit the regex. 如果将字符串封装在单引号中,请不要使用单引号来分隔正则表达式。
This should work: 这应该工作:
public function sortReferencesNumerically(){
$query = $this->createQuery();
$statement = 'select * from tx_referencemanager_domain_model_reference WHERE name REGEXP \'^[0-9]\' ORDER BY CAST(name as SIGNED INTEGER) ASC';
$query->statement($statement);
return $query->execute();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.