The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
function tablerowswitch() { static $tablerow_count; $tablerow_count++; if ($tablerow_count % 2) { echo "odd"; } else { echo "even"; } } ?>
In the body I have:
...
...
... so that I can format alternate rows as 'odd' and 'even'. The trouble is, if I have more than one table on a page, the $tablerow_count doesn't start at 1 for subsequent tables so the first row is formatted as 'even' instead of 'odd'. Example: [URL]http://timmargh.net/new_stuff.php[/URL] - note the first row of the second table is shaded, i.e. it's 'even' when it should be 'odd'.
Is there a piece of code I can stick in each table to reset $tablerow_count to 1? I know it's probably easier than finding water by falling off a boat, but I know zip about PHP and have tried various things without success.
$tablerow_count=0;
function tablerowswitch() {
global $tablerow_count;
$tablerow_count++;
if ($tablerow_count % 2) { echo "odd"; } else { echo "even"; }
}
?>
Use it as you've been doing so already. Everytime you want to reset the table counter, ie just before you want to start a new table, put
$tablerow_count=0;
:^(
> In the head of my page I have:
>
> function tablerowswitch() { static $tablerow_count;
> $tablerow_count++; if ($tablerow_count % 2) { echo "odd"; }
> else { echo "even"; } } ?>
>
> In the body I have:
>
> ...
>
>
> ...
>
> ... so that I can format alternate rows as 'odd' and 'even'. The
> trouble is, if I have more than one table on a page, the
> $tablerow_count doesn't start at 1 for subsequent tables so
> the first row is formatted as 'even' instead of 'odd'. Example:
> [URL]http://timmargh.net/new_stuff.php[/URL] - note the first row of
> the second table is shaded, i.e. it's 'even' when it should be
> 'odd'.
Define the function as:
function tablerowswitch($init_value=1)
{
$tablerow_count = $init_value;
$tablerow_count++; if ($tablerow_count % 2) { echo "odd"; }
else { echo "even"; }
}
?>
Then when you start a new table, just use tablerowswitch(1), and normally you would use tablerowswitch().
function tablerowswitch() { static $tablerow_count; $tablerow_count++; if ($tablerow_count % 2) { echo "odd"; } else { echo "even"; } } ?>
In the body I have:
...
...
... so that I can format alternate rows as 'odd' and 'even'. The trouble is, if I have more than one table on a page, the $tablerow_count doesn't start at 1 for subsequent tables so the first row is formatted as 'even' instead of 'odd'. Example: [URL]http://timmargh.net/new_stuff.php[/URL] - note the first row of the second table is shaded, i.e. it's 'even' when it should be 'odd'.
Is there a piece of code I can stick in each table to reset $tablerow_count to 1? I know it's probably easier than finding water by falling off a boat, but I know zip about PHP and have tried various things without success.