GetDotted Domains

Viewing Thread:
"Very basic PHP help"

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.

Sat 09/04/05 at 18:02
Regular
"Twenty quid."
Posts: 11,452
In the head of my page I have:



In the body I have:

...
Blah
Blah blah
...


... 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.
Sat 09/04/05 at 22:35
Regular
"Twenty quid."
Posts: 11,452
Ah, cheers!
Sat 09/04/05 at 21:29
Regular
"Devil in disguise"
Posts: 3,151
Put this in your header...

$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;
Sat 09/04/05 at 20:28
Regular
"Twenty quid."
Posts: 11,452
Cheers for the help, but now they're all coming up as 'even'.

:^(
Sat 09/04/05 at 18:49
Regular
"NULL"
Posts: 1,384
Timmargh wrote:
> In the head of my page I have:
>
> > $tablerow_count++; if ($tablerow_count % 2) { echo "odd"; }
> else { echo "even"; } } ?>

>
> In the body I have:
>
> ...
> Blah
> Blah blah
> ...

>
> ... 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:

{
$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().
Sat 09/04/05 at 18:02
Regular
"Twenty quid."
Posts: 11,452
In the head of my page I have:



In the body I have:

...
Blah
Blah blah
...


... 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.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Many thanks!
You were 100% right - great support!
Top-notch internet service
Excellent internet service and customer service. Top-notch in replying to my comments.
Duncan

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.