viper3two Posted March 6, 2006 Share Posted March 6, 2006 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 colorsEG: Blue first RowYellow 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 Quote Link to comment https://forums.phpfreaks.com/topic/4222-table-help/ Share on other sites More sharing options...
craygo Posted March 6, 2006 Share Posted March 6, 2006 Well you need to add some code before and after your loop to get it to alternate colors. Here is the codefirst we set the row color before the loop[code]$bgcolor = '#FFFF00'; //yellow cause you want to start with blue[/code]Then at the start of the loop we have a check to change the color if it is one or the other[code]if ($bgcolor == "#FFFF00"){ $bgcolor = "#0000FF";} else { $bgcolor = "#FFFF00";}[/code]Now we can put everything together[code]$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 colorsif ($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>";}[/code]Also the code to take out borders is border=0Ray Quote Link to comment https://forums.phpfreaks.com/topic/4222-table-help/#findComment-14710 Share on other sites More sharing options...
viper3two Posted March 6, 2006 Author Share Posted March 6, 2006 [!--quoteo(post=352154:date=Mar 6 2006, 01:51 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 6 2006, 01:51 PM) [snapback]352154[/snapback][/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 codefirst we set the row color before the loop[code]$bgcolor = '#FFFF00'; //yellow cause you want to start with blue[/code]Then at the start of the loop we have a check to change the color if it is one or the other[code]if ($bgcolor == "#FFFF00"){ $bgcolor = "#0000FF";} else { $bgcolor = "#FFFF00";}[/code]Now we can put everything together[code]$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 colorsif ($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>";}[/code]Also the code to take out borders is border=0Ray[/quote]Thank you Ray. I put in your code and read through it to understand how it works now. I appreciate your help!Tony Quote Link to comment https://forums.phpfreaks.com/topic/4222-table-help/#findComment-14732 Share on other sites More sharing options...
craygo Posted March 6, 2006 Share Posted March 6, 2006 Glad to help!! Quote Link to comment https://forums.phpfreaks.com/topic/4222-table-help/#findComment-14740 Share on other sites More sharing options...
obsidian Posted March 6, 2006 Share Posted March 6, 2006 [!--quoteo(post=352184:date=Mar 6 2006, 02:44 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 6 2006, 02:44 PM) [snapback]352184[/snapback][/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:[code]$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}[/code]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:[code]<table border="0" cellpadding="0" cellspacing="0">[/code]good luck Quote Link to comment https://forums.phpfreaks.com/topic/4222-table-help/#findComment-14747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.