PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

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 July 4th, 2002, 11:04 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Alternating Text Colours

just wondering what is wrong with this code..its spose to display each row of text with different colours...
php Code:
Original - php Code
  1.  
  2. <?php
  3. mysql_connect(localhost, username, password);
  4. mysql_select_db(database);
  5. $result = mysql_query("SELECT * FROM table");
  6. $result2 = mysql_query("SELECT COUNT(*) FROM table");
  7. $row2 = mysql_fetch_array($result2);
  8. while($row = mysql_fetch_array($result))
  9. {
  10.     if($row2['COUNT(*)'] / 2)
  11.     {
  12.         echo '<font face="Lucida Sans Unicode" size="2" color="#000066">';
  13.     }
  14.     else
  15.     {
  16.         echo '<font face="Lucida Sans Unicode" size="2" color="#CCCCCC">';
  17.     }
  18. }
  19. echo "{$row['something']}</font><br>";
  20.  
  21. ?>

it doesnt give me errors, it just displays all the text the same colour..

Reply With Quote
  #2  
Old July 4th, 2002, 11:50 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Alternating Text Colours

Try this:

php Code:
Original - php Code
  1.  
  2. <?php
  3. mysql_connect(localhost, username, password);
  4. mysql_select_db(database);
  5. $result = mysql_query("SELECT * FROM table");
  6. $i = 1;
  7. while($row = mysql_fetch_array($result))
  8. {
  9.     if(($quot = $i % 2) == 0)
  10.     {
  11.         echo '<font face="Lucida Sans Unicode" size="2" color="#000066">';
  12.     }
  13.     else
  14.     {
  15.         echo '<font face="Lucida Sans Unicode" size="2" color="#CCCCCC">';
  16.     }
  17. $i++;
  18. }
  19. echo "{$row['something']}</font><br>";
  20.  
  21. ?>

Reply With Quote
  #3  
Old July 4th, 2002, 12:03 PM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Alternating Text Colours


Quote:
just wondering what is wrong with this code..its spose to display each row of text with different colours...



Ooops, I will try to explain. You did this:
php Code:
Original - php Code
  1. if($row2['COUNT(*)'] / 2)
Which will always return true ( greater than 0 ) ... for a better explanation start here http://www.php.net/manual/en/language.types.boolean.php

The code that I sent you will use the color 000066 on false and CCCCCC on true. For more information on the % operator see http://www.php.net/manual/en/langua....arithmetic.php

Hope that helps.

Reply With Quote
  #4  
Old July 4th, 2002, 12:19 PM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Alternating Text Colours

For clarification, true is any non-zero value ( greater than or less than ). Not just greater than as I previously wrote.

My apologies.

Reply With Quote
  #5  
Old July 4th, 2002, 12:45 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Alternating Text Colours

Thanks for the help evilive..although, the code you gave me, didnt quite work...just for the record, i hate to change this:
php Code:
Original - php Code
  1.  
  2.     }
  3. $i++;
  4. }
  5. echo "{$row['something']}</font><br>";

to this
php Code:
Original - php Code
  1.  
  2. $i++;
  3. echo "{$row['something']}</font><br>";
  4. }


just had to put the echo something inside the while loop

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Alternating Text Colours


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway