Im using this code to show the number of registers I have in tt_address in Page ID 68, and works fine, except that it doesnt show the hidden elements.
# 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
}
}
}
}
How could I count also the hidden records?
I think it is not possible to get hidden records using typoscript (no records from hidden, timed or access-protected pages can be selected!). Reference link: http://wiki.typo3.org/TSref/select
You may need to use "userfunc" as given below:
Typoscript:
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;
}
}
?>
You can't bypass the "enable fields" where clauses in a normal way, but TYPO3 allows to hack around that using a UNION
query:
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
}
An alternative solution:
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
}
}
}
}
Thanks cweiske for giving me this idea.
This is the way: eg Showing deleted or hidden pages only
table = pages
select.pidInList = 1
select.where = deleted=1 or hidden=1 UNION SELECT * FROM pages WHERE 1=0
This works 'cause the enablefields are appended to the query. Union with 1=0 where clause returns nothing with the enablefields.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.