473,320 Members | 1,713 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,320 software developers and data experts.

Table with different colors

Can anyone point out the error in this script? I have tried so many times but haven't been successful.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?
  5. $colors=ARRAY(
  6. "#000000","#000033","#000066","#000099","#0000CC","#0000FF","#003300",
  7. "#003333","#003366","#003399","#0033CC","#0033FF","#006600","#006633",
  8. "#006666","#006699","#0066CC","#0066FF","#009900","#009933","#009966",
  9. "#009999","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99",
  10. "#00CCCC","#00CCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC",
  11. "#00FFFF");
  12. ?>
  13.  
  14. <table border="0" cellspacing="1" cellpadding="0">
  15. <tr>
  16. <?
  17. for($i=0; $i< count($colors); $i++) {
  18. echo '<td>
  19. <table name="'.$colors[$i].'" width=10 height=10 border="0" bgcolor="'.$colors[$i].'">
  20.         <tr>
  21. <td><img src="_blank.gif" width="1" height="1" border="0" alt=""></td>
  22.         </tr>
  23. </table>
  24. </td>';
  25.  
  26. if ( (($i+1) % 6) == 0 ) echo $newrow="</tr><tr>"; // change 6 to 8 and see
  27. }
  28.  
  29. ?>                 
  30. </tr>
  31. </table>
  32. </body>
  33. </html>
Sep 9 '07 #1
11 1860
pbmods
5,821 Expert 4TB
Heya, Zion. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

I'm going to go ahead and move this thread to the PHP forum, where our resident Experts will be better able to help you out.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Sep 9 '07 #2
This code is supposed to create a table with different color windows but it does not even run. Just displays a line of the source code.
Sep 9 '07 #3
i copied your code and tested in my system and it is working... i am using xampp(integration of apache php and mysql)... what is next???
Sep 9 '07 #4
It is working if saved as php file. Now, how can I use it to display thumbs of a series of pics?
thanks


i copied your code and tested in my system and it is working... i am using xampp(integration of apache php and mysql)... what is next???
Sep 9 '07 #5
Staria
7
Hi...

Not sure if this is what you have in mind, but the following is a portion of the code I use on my websites to create a table with alternate row colors.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($sql ,$db);
  2. if ($myrow = mysql_fetch_array($result)) {
  3. do {
  4. if ($rowcolor == 1) {
  5. $rowcolorhex = "#FFFFFF";
  6. $rowcolor = 0;
  7. } else {
  8. $rowcolorhex = "#404040";
  9. $rowcolor = 1;
  10. }
  11.  
Hope this helps. :o)

If you need help finishing out the table like I mentioned above, let me know and I'll see what I can do to help. :o)

Staria
Sep 10 '07 #6
Thanks Staria
What I am thinking is instead of colors that are displayed in a row, I want to use some jpg images and display them as thumbnails.

Hi...

Not sure if this is what you have in mind, but the following is a portion of the code I use on my websites to create a table with alternate row colors.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query($sql ,$db);
  2. if ($myrow = mysql_fetch_array($result)) {
  3. do {
  4. if ($rowcolor == 1) {
  5. $rowcolorhex = "#FFFFFF";
  6. $rowcolor = 0;
  7. } else {
  8. $rowcolorhex = "#404040";
  9. $rowcolor = 1;
  10. }
  11.  
Hope this helps. :o)

If you need help finishing out the table like I mentioned above, let me know and I'll see what I can do to help. :o)

Staria
Sep 10 '07 #7
pbmods
5,821 Expert 4TB
Heya, Zion.

Instead of using background colors, use an array of image URLs (or fetch them from a database) and then output img tags, one per table cell.

PS., this code will execute a bit faster:
Expand|Select|Wrap|Line Numbers
  1. for($i=0, $len = count($colors); $i < $len; ++$i) 
  2.  
This way, you're not evaluating count($colors) (which never changes) at every single loop execution. Also, pre-incrementing (++$i) is faster in PHP than post-incrementing ($i++).
Sep 10 '07 #8
Thanks for the code. However, I created a folder and put like 20 images in it and changed all the "#0000???" in the above array, color codes to "1.jpg", "2.jpg", etc..
but the pictures do not show. Also I changed the width and height to 60 so it is pretty decent size. Othewise when using the above array the colors show no problem. What am I doing wrong?


Heya, Zion.

Instead of using background colors, use an array of image URLs (or fetch them from a database) and then output img tags, one per table cell.

PS., this code will execute a bit faster:
Expand|Select|Wrap|Line Numbers
  1. for($i=0, $len = count($colors); $i < $len; ++$i) 
  2.  
This way, you're not evaluating count($colors) (which never changes) at every single loop execution. Also, pre-incrementing (++$i) is faster in PHP than post-incrementing ($i++).
Sep 11 '07 #9
pbmods
5,821 Expert 4TB
Heya, Zion.

What does your code look like now?
Sep 11 '07 #10
Heya, Zion.

What does your code look like now?
Remember all the jpg files are in the same folder as this file.
Looks like this: Can you please let me know what is wrong? I am going to change the other color codes to other jpg files if I make it work.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?
  5. $colors=ARRAY(
  6. "1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","#0000FF","#003300",
  7. "#003333","#003366","#003399","#0033CC","#0033FF","#006600","#006633",
  8. "#006666","#006699","#0066CC","#0066FF","#009900","#009933","#009966",
  9. "#009999","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99",
  10. "#00CCCC","#00CCFF","#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC",
  11. "#00FFFF");
  12. ?>
  13.  
  14. <table border="0" cellspacing="1" cellpadding="0">
  15. <tr>
  16. <?
  17. for($i=0, $len = count($colors); $i < $len; ++$i) {
  18. echo '<td>
  19. <table name="'.$colors[$i].'" width=60 height=60 border="0" 
  20.  
  21. bgcolor="'.$colors[$i].'">
  22.         <tr>
  23. <td><img src="_blank.gif" width="1" height="1" border="0" alt=""></td>
  24.         </tr>
  25. </table>
  26. </td>';
  27.  
  28. if ( (($i+1) % 32) == 0 ) echo $newrow="</tr><tr>"; // change 6 to 8 and see
  29. }
  30.  
  31. ?>                 
  32. </tr>
  33. </table>
  34. </body>
  35. </html>
Sep 11 '07 #11
pbmods
5,821 Expert 4TB
ZionLion, please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

Don't make me ask again.
Sep 11 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
16
by: karlman | last post by:
I am trying to create a web page that shows a calendar schedules. I am attempting to use table cells with fixed widths and different colors to display this. It seems that IE6 doesn't always...
2
by: Emily Jones | last post by:
That subject line will have Joe Celko apoplectic!! Let's say I have this thing. Oh, I don't know, a car. No, a vehicle. Can we agree that is an entity type? Some attributes might be VIN, Fuel,...
7
by: Dave | last post by:
Are there any add-on products or samples available that can do the following in an vb.net datagrid I want to compare 2 rows in a datagrid - one row from one database and another row for another...
12
by: Adam Hartshorne | last post by:
Hi All, I was wondering if somebody could post a few lines of code which would produce random colors, which will be used in defining different regions on a mesh. So in addition to having n...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
7
by: Will Hartung | last post by:
I have a simple rule: ..main p { font-size: small; color: red;} But if I put a paragraph in a TABLE, it basically comes out black and a different size. I found if I did: ..main table {...
1
by: nirmala26 | last post by:
Hi All, I am using C#.net to develop a web application. I have a gridview and a table displaying two different lists of data. I want to have the backcolor of the cell (of both gridview and table)...
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...
0
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...
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: 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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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

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.