473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

the function to switch values ie for alternating between 2 colors in table display

Hi all!

What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!

Kind regards

Marc

Jul 12 '06 #1
4 1103
it has something like this in it somehere:

for($i=0; $i<10; $i++) {
echo $i % 2 ? $catodd : $cateven;
}

monomaniac21 wrote:
Hi all!

What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!

Kind regards

Marc
Jul 12 '06 #2
Message-ID: <11*********************@s13g2000cwa.googlegroups. comfrom
monomaniac21 contained the following:
>
What is the php function called which allows you to alternate between
two values? I've completely forgotten it and my searches in php.net
have not been fruitful!
There is a function?

I usually just do something like this

$rowstyle=($count%2!=1)?" style='background-color:#ddd'":"
style='background-color:#fff'";
$count++;

for each table row.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 12 '06 #3

I prefer

$linestyle = 1

While (criteria)
{
.......
$lineclass = "lineclass" . $linestyle;
<TR class = $lineclass><TD></TD></TR>;

$linestyle = 1 - $linestyle;
}

and set up two classes called lineclass0 and lineclass1

personally I think it is easier to read and control.

Jul 12 '06 #4
monomaniac21 wrote:
it has something like this in it somehere:

for($i=0; $i<10; $i++) {
echo $i % 2 ? $catodd : $cateven;
}
Just use an array:

$class = array('blue', 'red');

echo $class[$i%2];

Jul 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: LRW | last post by:
Is there some way to make a table have alternating colors for rows when you're generating the table data with a WHILE statement? You know, row 1 has a gray BG, row 2 is white, row 3 is gray, 4 is...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: bettyann | last post by:
i am using templates via HTML_Template_IT to create a table from the results of a mysql query. i wanted to change the background image of alternating rows in the table. i thought i could do this...
10
by: Paul | last post by:
Trying to write a function that does the following: Joe gets 100 points for every 30 widgets he sells. So if he sells less than thirty he gets nothing. If he gets between 30 and 59 he gets...
2
by: Ralph Snart | last post by:
Is there a way to alternate table row colors without using the position() mod 2 trick? I'm in a series of nested xsl:for-each elements, about 3 deep, and I want to alternate the table row color...
47
by: Matt Kruse | last post by:
http://www.mattkruse.com/temp/css_expressions.html One of the standard CSS questions is "how can I shade every other table row a different color with CSS?" The answers are usually 1) you can't...
1
by: Steve Bottoms | last post by:
Hi, all! How does one prevent table cell background colors from alternating between grey and white? I've dropped a basic table control on an ASP.Net page (using VB.Net codebehind), and...
5
by: | last post by:
I'm making admin forms. I'm wondering if there is a way to have the server programmatically assign alternating colors in a regular table (not a datalist control). I notice ASP.NET 2 offers a...
3
clintw
by: clintw | last post by:
Hi all, I've been doing my head in trying to get this to work, but I keep running into a snag. Basically I have a database table with a list of events for the year, with fields for Month, Event...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.