Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 16th, 2002, 06:42 PM
ResNet9 ResNet9 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 101 ResNet9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via AIM to ResNet9
alternating row colors

I want to alternate the color of the rows in a table that I am pulling off a database. I tried taking the variable
Code:
$i
from the for loop
Code:
($i = 0....)
and then doing
Code:
$i % 2 = $result
. If
Code:
$result
is 0 I want one color or if !$result = 0;

Any thoughts would help

Reply With Quote
  #2  
Old August 16th, 2002, 07:28 PM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: alternating row colors

heres a good way to do it:
php Code:
Original - php Code
  1.  
  2.   $result = mysql_query("SELECT * FROM RM_posts WHERE tid = '{$_GET['tid']}'");
  3.   $num = mysql_num_rows($res);
  4.  
  5.     if(($quot = $i % 2) == 0)
  6.     {
  7.         echo "<td height="20" width="20%" valign="top" bgcolor="#0066CC">You text here</font>";
  8. }else{
  9. echo "<td height="20" width="20%" valign="top" bgcolor="#9966CC">You text here</font>";
  10. }
  11. echo "</td>";


hope that is of some assistance cheif..

Reply With Quote
  #3  
Old August 19th, 2002, 01:18 AM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to Gipz
RE: alternating row colors

Place this in your loop:

$bgcolor = ($bgcolor == "black" ? "white" : "black");

echo ('<td height="20" width="20%" valign="top" bgcolor="'.$bgcolor.'">You text here</font>';

Reply With Quote
  #4  
Old August 20th, 2002, 01:52 AM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: alternating row colors

very sweet code!!! I thought I had an efficient method with this:

php Code:
Original - php Code
  1.  
  2. $count ++;
  3. $bgcolor = (($count % 2) == 0 ? "#eeeeee" : "#cccccc");

but yours is better,
B

Reply With Quote
  #5  
Old August 20th, 2002, 01:55 AM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: alternating row colors

would this work?
php Code:
Original - php Code
  1.  
  2. $bgcolor = (($count++ % 2) == 0 ? "#eeeeee" : "#cccccc");

I think I'll check,
B

Reply With Quote
  #6  
Old August 20th, 2002, 04:59 AM
siteworkspro.com siteworkspro.com is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 92 siteworkspro.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to siteworkspro.com Send a message via AIM to siteworkspro.com
RE: alternating row colors

it would be like,

while(condition)
{
$bgcolor = ($bgcolor == "color1" ? "color2" : "color1");

echo '<td bgcolor="$bgcolor">'?
}

Reply With Quote
  #7  
Old August 23rd, 2002, 04:22 PM
ResNet9 ResNet9 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 101 ResNet9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via AIM to ResNet9
RE: alternating row colors

I'm not sure I know how your code works siteworkspro.com. I don't think that I understand how the variables would switch.

Reply With Quote
  #8  
Old August 23rd, 2002, 11:14 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: alternating row colors

the other three above it all work fine...

Reply With Quote
  #9  
Old August 24th, 2002, 01:05 PM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via ICQ to Gipz
RE: alternating row colors

I can break it up for you:

$bgcolor = ($bgcolor == "color1" ? "color2" : "color1");

[var to contain value] = ([condition] ? [return this if condition is true] : [return this if condition is false]);

Reply With Quote
  #10  
Old August 25th, 2002, 01:51 AM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 5
Send a message via Yahoo to bakertrg
RE: alternating row colors

It was the while loop that through me because of the word condition. I started thinking that this was the condition being checked to flip the colors. I use the ternary operator (? for this myself, I just use the modulo (%) as my condition but I like yours better gipz.

B

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > alternating row colors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek