Jump to content


Photo

table help


  • Please log in to reply
4 replies to this topic

#1 viper3two

viper3two
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 05:33 PM

Just a quick question, I have a table that will display an employee's demographics.
What is the code to make the borders not visible, and also to change the cell row colors
EG: Blue first Row
Yellow second row and alternate back and forth?

Here is what I have, it works, but it is just a plain vanilla table:

$display_block .= "
<table cellpadding=3 cellspacing=2 border=1 width=98%>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Title</th>
<th>Picture</th>
</tr>";
while ($newArray = mysql_fetch_array($result)) {
$empnumber = $newArray['EmpNo'];
$firstname = $newArray['FstName'];
$lastname = $newArray['LstName'];
$title = $newArray['Title'];
$department = $newArray['HmDept'];
$picfile = $newArray['PictureFile'];
$display_block .= "<tr>
<td align=center>$lastname <br> </td>
<td align=center>$firstname <br> </td>
<td align=center>$title <br> </td>
<td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td>
</tr>";
}

and then in the HTML:

<html>
<head>
<title>Administration</title>
</head>
<body>
<p align="center"><a name="top" id="top"></a></p>
<p align="center"><a name="top" id="top"></a></p>
<p align="center"><font face="Arial" size="3">Administration</font></p>
<?php echo $display_block; ?>


</body>
</html>

Thanks for the reply in advance! You guys are awesome!
Tony


#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 06 March 2006 - 06:51 PM

Well you need to add some code before and after your loop to get it to alternate colors. Here is the code

first we set the row color before the loop
$bgcolor = '#FFFF00'; //yellow cause you want to start with blue

Then at the start of the loop we have a check to change the color if it is one or the other
if ($bgcolor == "#FFFF00"){
  $bgcolor = "#0000FF";
} else {
  $bgcolor = "#FFFF00";
}

Now we can put everything together
$bgcolor = '#FFFF00'; //yellow cause you want to start with blue
$display_block .= "
<table cellpadding=3 cellspacing=2 border=0 width=98%>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Title</th>
<th>Picture</th>
</tr>";
while ($newArray = mysql_fetch_array($result)) {
// altername the colors
if ($bgcolor == "#FFFF00"){
  $bgcolor = "#0000FF";
} else {
  $bgcolor = "#FFFF00";
}
$empnumber = $newArray['EmpNo'];
$firstname = $newArray['FstName'];
$lastname = $newArray['LstName'];
$title = $newArray['Title'];
$department = $newArray['HmDept'];
$picfile = $newArray['PictureFile'];
$display_block .= "<tr bgcolor=$bgcolor>
<td align=center>$lastname <br> </td>
<td align=center>$firstname <br> </td>
<td align=center>$title <br> </td>
<td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td>
</tr>";
}

Also the code to take out borders is border=0

Ray


#3 viper3two

viper3two
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 March 2006 - 07:28 PM

[!--quoteo(post=352154:date=Mar 6 2006, 01:51 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 6 2006, 01:51 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Well you need to add some code before and after your loop to get it to alternate colors. Here is the code

first we set the row color before the loop
$bgcolor = '#FFFF00'; //yellow cause you want to start with blue

Then at the start of the loop we have a check to change the color if it is one or the other
if ($bgcolor == "#FFFF00"){
  $bgcolor = "#0000FF";
} else {
  $bgcolor = "#FFFF00";
}

Now we can put everything together
$bgcolor = '#FFFF00'; //yellow cause you want to start with blue
$display_block .= "
<table cellpadding=3 cellspacing=2 border=0 width=98%>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Title</th>
<th>Picture</th>
</tr>";
while ($newArray = mysql_fetch_array($result)) {
// altername the colors
if ($bgcolor == "#FFFF00"){
  $bgcolor = "#0000FF";
} else {
  $bgcolor = "#FFFF00";
}
$empnumber = $newArray['EmpNo'];
$firstname = $newArray['FstName'];
$lastname = $newArray['LstName'];
$title = $newArray['Title'];
$department = $newArray['HmDept'];
$picfile = $newArray['PictureFile'];
$display_block .= "<tr bgcolor=$bgcolor>
<td align=center>$lastname <br> </td>
<td align=center>$firstname <br> </td>
<td align=center>$title <br> </td>
<td align=center><img src=/EmployeeDirectory/database/$picfile> <br> </td>
</tr>";
}

Also the code to take out borders is border=0

Ray
[/quote]

Thank you Ray. I put in your code and read through it to understand how it works now. I appreciate your help!
Tony

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 06 March 2006 - 07:44 PM

Glad to help!!

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 March 2006 - 07:55 PM

[!--quoteo(post=352184:date=Mar 6 2006, 02:44 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 6 2006, 02:44 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Glad to help!!
[/quote]

here's a little simplified (well, at least in AMOUNT of code ;-)) version that i like to use:

$color = "#4444ee";
while ($row = mysql_fetch_array($sql)) {
  $color = $color == "#4444ee" ? "#ffffff" : "#4444ee;
  echo "<tr style='background-color: $color;'>\n";
  // then, print the rest of your row
}

also, try to get into the habit of using quotes around the value of EVERY attribute in your markup. your code won't validate without it! for instance:
<table border="0" cellpadding="0" cellspacing="0">

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users