Jump to content

[SOLVED] Alternate row colors in table


Grant Holmes

Recommended Posts

Im correctly alternating my row color.

 

Here's my page code that works:

<?php include_once("security/SECsecurity.php"); ?>
<?php $DOCROOT = $_SERVER['DOCUMENT_ROOT'] ; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>MySite  Inactive Requests</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">
    <META NAME="ROBOTS" CONTENT="NONE">
    <LINK REL="stylesheet" TYPE="text/css" HREF="martini.css">
<script src="JS/sorttable.js"; ?></script>
</HEAD>
<BODY>
<a name="top"></a>
<?php
include("dbinfo.inc.php");
mysql_connect(mysql,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
          
$query="SELECT * FROM birthdays WHERE Event='request' AND Active='0'";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();

echo "<A name=\"top\"></A><b><center><H1>MySite \"<I>Inactive Requests</I>\":</H1>";
?>

<center><div style='width:100%; background-color:silver; text-align:right'>
  <?php SECShowAdminLink(); ?>
   
  <?php SECShowLogoutLink(); ?>  <A href="data.php">Main Data Page</A>  
</div>
<center><div style='width:100%; background-color:#ffe4c4; text-align:center'><BR>This page is showing <I>INACTIVE</I> Requests</B><BR><A href="requests.php">view <I>ALL</I> </A>   <A href="requests_active.php">view active only</A></div></center>
<table border="1" cellspacing="2" cellpadding="3" class="sortable">
<tr> 
	<TH valign="top">From:</TH>
	<TH valign="top">City</TH>	
	<TH valign="top">State</TH>			
	<TH valign="top">Zip</TH>			
	<TH valign="top">Country</TH>				
         <TH valign="top">Artist Name</TH>
         <TH valign="top">Song Title</TH>
         <TH valign="top">Submitted</TH>			
         <TH valign="top">Status</TH>	
         <TH valign="top"> </TH>		
</tr>

<?php
$i=0;
while ($i < $num) {
$Active=mysql_result($result,$i,"Active");
$firstname=mysql_result($result,$i,"Contact_Info_FirstName");
$lastname=mysql_result($result,$i,"Contact_Info_LastName");
$city=mysql_result($result,$i,"Contact_Info_City");
$state=mysql_result($result,$i,"Contact_Info_State");
$zip=mysql_result($result,$i,"Contact_Info_ZipCode");
$country=mysql_result($result,$i,"Contact_Info_Country");
$email=mysql_result($result,$i,"Contact_Info_Email");
$Bfirstname=mysql_result($result,$i,"Birthday_Info_FirstName");
$Blastname=mysql_result($result,$i,"Birthday_Info_LastName");
$Bcity=mysql_result($result,$i,"Birthday_Info_City");
$Bstate=mysql_result($result,$i,"Birthday_Info_State");
$Bzip=mysql_result($result,$i,"Birthday_Info_ZipCode");
$Bcountry=mysql_result($result,$i,"Birthday_Info_Country");
$Date=mysql_result($result,$i,"DateEntered");
$id=mysql_result($result,$i,"id"); 

?>
</form>
<?php
//Alternate Row Color
if($i % 2) 
	{ 
	echo '<TR bgcolor="silver">';
	} 
else 
	{ 
	echo '<TR bgcolor="#ffffff">';
	}
?>		

            <td valign="top"><input type="hidden" name="ud_id" value="<? echo $id; ?>">
            <STRONG><?php echo "$firstname $lastname"; ?></STRONG><BR><a href="mailto:<?php echo "$email"; ?>"><?php echo "$email"; ?></a></TD>
            <TD valign="top"><?php echo "$city"; ?></TD>
            <TD valign="top"><?php echo "$state"; ?></TD>	
            <TD valign="top"><?php echo "$zip"; ?></TD>			   	   
            <TD valign="top"><?php echo "$country"; ?></TD>	   		   
            <TD valign="top"> <?php echo "$Bfirstname"; ?></TD>
            <TD valign="top"> <?php echo "$Blastname"; ?></TD>
            <TD valign="top"><?php echo "$Date"; ?></TD>				   
            <TD valign="top"> <B>Active?: 
<?php
$checked = $Active ? "checked" : "";
echo "<input type=\"checkbox\" name=\"foo\" $checked>";
?>
 </td>
            <TD valign="top"><CENTER> <a href='requests_edit.php?id=<? echo "$id"; ?>'>edit</a><BR><A href="#top"><IMG src="images/uparrow.gif" border="0" hspace="2" vspace="4" /></A><A href="#bottom"><IMG src="images/downarrow.gif" border="0" hspace="4" vspace="4" /></A></CENTER></TD>
</TD>
</tr>
<?php
++$i;
} 
echo "</table><P><A href=\"#top\">Back to top</A></P></B><BR>";
?>

<BR><BR><BR>
           <?php include "include/footer.php"; ?>	
	  <a name="bottom"></a>
</BODY>
</html>


 

However, when I use the javascript titles to resort the rows, the color stays with the row. This is not a HUGE deal, but would be nice to fix.

 

Is this a javascript issue? IOW, should I handle this in the javascript? or can we fix it in the PHP?

Link to comment
Share on other sites

im pretty sure that your JS is rearranging how the rows are ordered (taking one tr and moving it ahead of another etc). And because you define the row color like '<TR bgcolor="#ffffff">' that info is being moved as well.

 

A solution would be to do the row coloring with javascript after the page loads and then recall that function upon a sort, or fix your javascript so that it only moves the data and not the actual rows (tr)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.