Jump to content

How to make a background like this?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
I've seen a site with a table and it has a background like this:
Posted Image

How can i make this background myself using css and php?

#2
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
i've made it myself to work it out. I've done this with php
first off theres an array with the colors:
	$colors = array("#E9F0FF", "#FFFFFF");
Then theres a loop for the rows:

	for ($i = 0; $i < 21; $i ++) { /*20 rows*/
		$color = $colors[$colorCount];
		echo "<tr bgcolor='$color'>
		<td>Value</td>
		<td>More value</td>
		</tr>";
		$colorCount++;
	}
Now, in the loop which spawns the rows, i made a little statement which tells them when to reset the value to 0.

		if ($colorCount > count($colors) - 1) {
			$colorCount = 0;
		}
And it works so yay!
I hope you guys will use or at least learned from this as i answered the question myself.

DuNnkers.

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
If you're wishing for something more code correct, here is a more simpler option:

<?php
print "<TABLE BORDER=\"1\">\n";
print "<TR bgcolor=\"lightblue\"><TD>Foo</TD><TD>Two</TD><TD>Thre</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($result); //get a row from our result set
    if($i % 2) { //this means if there is a remainder
        print "<TR bgcolor=\"lightblue\">\n";
    } else { //if there isn't a remainder we will do the else
        print "<TR bgcolor=\"white\">\n";
    }
    print "<TD>".$row['foo']."</TD><TD>".$row['two']."</TD><TD>".$row['three']."</TD>\n";
    print "</TR>\n";
}

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Aha, that's indeed a better method, to use if($i % 2) ..
Ill be using it thanks.

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
nvm, a moderator may delete this post if you stumble upon it :D

#6
marjie

marjie

    Newbie

  • Members
  • Pip
  • 6 posts
why?