01042: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows

Summary: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows
Created: 2008-08-28 14:32
Status: Closed - not a bug
Category: Bug
From: bwills
Assigned:
Priority: 42
Version: 2.2.0-beta65
OS: OS: RHEL ES 4.0/Apache 2.0.52/PHP 4.3.9

Description: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows

Reference recipe: FormattingTables

Recipe excerpt: an administrator might choose to give each row a unique class attribute by row number: $TableRowAttrFmt = "class='row\$TableRowCount'";

This code functions correctly as far as alternating row color is concerned, but does not preserve cosmetics in a special case. When a table has an odd number of rows the even/odd row coloring will switch for subsequent tables on the same page. For short tables this is actually quite an eyesore because row 1 will visually clash with the header row.

This problem is due to loose management of the static variable $rowcount, in function FormatTableRow, file pmwiki.php, which maintains the even/odd row state across function calls.

Small changes to two files in the wiki core corrected this issue at my site:

$ diff pmwiki.php.orig pmwiki.php
1339c1339
< function FormatTableRow($x, $sep = '\\|\\|') {
---
> function FormatTableRow($x, $sep = '\\|\\|', $reset_count = false) {
1342a1343,1346
>   if ($reset_count) {
>     $rowcount = 0;
>     return '';
>   }
$ diff stdmarkup.php.orig  stdmarkup.php
375c375
<     .'<:block,1>'");
---
>     .'<:block,1>'.FormatTableRow(0,0,true)");

Hi. I seem unable to reproduce this bug, all tables start with a green row. Maybe you need to use $TableRowIndex instead of $TableRowCount to have repeating alternate styles? --Petko June 15, 2009, at 08:44 AM

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_COOKIE] => PHPSESSID=nacd9pb18m9041ljha6j6g2up5; imstime=1777497450
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=PITS%2f01042
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=PITS%2f01042
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/PITS/01042
            [REDIRECT_SCRIPT_URL] => /wiki/PITS/01042
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afJ1fnJ89WyShLD_WNqx_gAAAFI
            [REDIRECT_URL] => /wiki/PITS/01042
            [REMOTE_ADDR] => 216.73.216.31
            [REMOTE_PORT] => 60440
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/PITS/01042
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/PITS/01042
            [SCRIPT_URL] => /wiki/PITS/01042
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afJ1fnJ89WyShLD_WNqx_gAAAFI
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777497470.8011
            [REQUEST_TIME] => 1777497470
            [argv] => Array
                (
                    [0] => n=PITS%2f01042
                )

            [argc] => 1
        )

)