TYPO3:选择包含隐藏行的计数(*)

时间:2013-02-06 14:54:35

标签: sql select typo3 typoscript

我使用此代码显示我在页面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
      }
    }
  }
}

我怎么能算出隐藏的记录?

4 个答案:

答案 0 :(得分:1)

我认为使用typoscript无法获取隐藏的记录(不能选择隐藏,定时或访问保护页面中的记录!)。 参考链接:http://wiki.typo3.org/TSref/select

您可能需要使用“userfunc”,如下所示:

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;
 }
}
?>

答案 1 :(得分:0)

您无法以正常方式绕过子句中的“启用字段”,但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
}

答案 2 :(得分:0)

另一种解决方案:

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给我这个想法。

答案 3 :(得分:0)

这是方式:例如仅显示已删除或隐藏的页面

table = pages
select.pidInList = 1
select.where = deleted=1 or hidden=1 UNION SELECT * FROM pages WHERE 1=0

这有效'因为启用字段会附加到查询中。 Union with 1 = 0 where子句不返回enablefields。