[英]TYPO3: Select count(*) where the hidden rows are included
我使用此代碼顯示我在頁面ID 68的tt_address中擁有的寄存器數,並且工作正常,但它不顯示隱藏的元素。
# Default PAGE object:
page = PAGE
page{
20 = CONTENT
20 {
table = tt_address
select{
selectFields = count(uid) AS count
pidInList = 68
where = deleted = 0
}
renderObj = COA
renderObj {
10 = TEXT
10 {
value = Status: {field:count}
insertData = 1
}
}
}
}
我又如何計算隱藏的記錄?
我認為不可能使用錯字來獲取隱藏的記錄(無法選擇隱藏,定時或受訪問保護的頁面中的記錄!)。 參考鏈接: http : //wiki.typo3.org/TSref/select
您可能需要使用“ userfunc”,如下所示:
Typo腳本:
includeLibs.showHiddenElements = fileadmin/lib/showHiddenElements.php
page.20 =USER
page.20 {
userFunc =user_showHiddenElements->main
field = uid
table = tt_address
where = deleted = 0 and pid = 68
}
fileadmin / lib / showHiddenElements.php:
<?php
class user_ShowHiddenElements {
function main($content, $conf){
$res= $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
$conf[field], // SELECT ...
$conf[table], // FROM ...
$conf[where], // WHERE...
'', // GROUP BY...
'', // ORDER BY...
'' // LIMIT ...
);
return $res;
}
}
?>
您不能以正常方式繞過“啟用字段” where子句,但是TYPO3允許使用UNION
查詢來解決:
select {
selectFields = count(uid) AS count
pidInList = 68
where.data = TSFE:id
# we hack our way around the enablefields restriction
where.wrap = 0 UNION SELECT COUNT(*) as count FROM tt_address WHERE pid = 68
}
替代解決方案:
page{
24 = CONTENT
24.wrap = <div class="status_count">|</div>
24 {
table = tt_address
select {
selectFields = count(uid) AS count
pidInList = 68
where.data = TSFE:id
# we hack our way around the enablefields restriction
where.wrap = |0 UNION SELECT COUNT(*) as count FROM tt_address WHERE pid = 68
}
renderObj = COA
renderObj {
10 = TEXT
10.wrap = |</div><div style="display:none">
10 {
value = Status: {field:count}
insertData = 1
}
}
}
}
感謝cweiske給我這個主意。
這是這樣的:例如,僅顯示已刪除或隱藏的頁面
table = pages
select.pidInList = 1
select.where = deleted=1 or hidden=1 UNION SELECT * FROM pages WHERE 1=0
這是因為將enablefields附加到查詢中。 與1 = 0並集,其中子句與enablefields一起不返回任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.