SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me Control Alternating Color Script

    I have a script that imparts alternating colors to table cells. At least it did; I hope I haven't mangled it.

    Unfortunately, it seems to interfere with everything else, so I'd like to try and move it out of the way. As you can see, it's separating two "$block" sections. I'd like to at least move it above BLOCK #1 so I can consolidate the two $block sections. If possible, I'd like to move it above my query, too.

    I just want it out of the way so I can continue to modify my script without constantly tripping over this color script.

    Thanks.

    PHP Code:

    // BLOCK #1

    $block "<table class=\"sortphp_ref\" id=\"Table2\" style=\"margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;\">";
    $block .="<thead>
    <tr><th style=\"background: #666; color: #fff;\">Places</th>
    <th style=\"background: 
    $BG; color: #fff;\">Orders</th></tr>
    </thead>
    <tbody>"
    ;



    // ALTERNATING COLOR SCRIPT...

        
        // Count colors, used to determine which color set to use.
        
    $cset_size sizeof($color_sets);
        
        
    $i 0;
        while (
    $row mysql_fetch_array ($res)) {
            
    // Determine color set
            
    $c $i $cset_size;


    // BLOCK #2

    $block .= '<tr>';
    $block .= '<td>' $row['mammalorder'] . '</td>';
    $block .= '<td>XXX</td>';
    $block .= '</tr>'

  2. #2
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this helps...

    Code:
    # this function chooses a color depending on whether it is an odd or even number.
    function setrowcolor($i, $row_bgcolor1, $row_bgcolor2) {
    	if ($i % 2) { 
    	    return $row_bgcolor1; 
    	} else { 
    		return $row_bgcolor2; 
    	}
    } // end function
    
    # replace color1 and color2 with your colors
    # you have to loop through the records, or calculate the total size of iterations.
    # alternatively you could do a normal while/wend loop and set up $i as a counter that
    # increases for every loop.
    
    for ($i = 0; $i < NUMBER_OF_RECORDS; $i++) {
       $setColor=setrowcolor($i, COLOR1, COLOR2);
       ?>
       <tr bgcolor="<?=$setColor;?>">
        ... your table row data ...
       </tr>
       <?php
    } # next

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but the script I'm using lets you alternate colors independently on different columns. You can see an example at http://www.geosymbols.org/animals/insects/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •