SitePoint Sponsor

User Tag List

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

    Need to Modify Alternate Table Cell Colors Script

    Near the top of http://www.geosymbols.org/animals/insects/ is a table with alternating row colors with a twist - the colors are different in each column.

    This is the script I'm using:

    PHP Code:
        // 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;

      
    // This line may need to be modified,
      // not sure what was going on with "{$row[]} {$row[]}"
      
    $block .= "<tr>";
    //  $block .= "<td class = \"tdname\" style='background-color:" . $color_sets[$c][0] . "'>' . echo $sub_row[0] . '</td>";
      
    $block .= "<td class = \"tdname\" style='background-color:" $color_sets[$c][0] . "'>{$row["Area"]}</td>";
      
    $block .= "<td class = \"tdsymbol\" style='background-color:" $color_sets[$c][1] . "'><a href='$LinkSymbol'>{$row['Family']}</a> ({$row['FamilyCommon']})</td>";
    //  $block .= "<td class = \"tdsymbol\" style='background-color:" . $color_sets[$c][1] . "'>$Locations' . $Locations . '</td>";
      
    $block .= "</tr>";
      
    $i++;
        }
      
    $block .= "</tbody></table>";
        
        echo 
    $block;

    I had a lot of trouble working with the colors script, which seems to interfere with other functions. I've finally found a script that accomplishes my main objective. Now I just need to incorporate the alternating cell colors script - or find a new solution.

    Below is my new script, with the table cell color script pasted into position. I THINK the problem is the last bracket, which I've noted. I've moved the bracket to various locations, but nothing works.

    Ideally, I'd like to modify the colors script...

    PHP Code:
    $cset_size sizeof($color_sets);
        
        
    $i 0;
        while (
    $row mysql_fetch_array ($res)) {
            
    // Determine color set
            
    $c $i $cset_size
    ...so that it's easier to work with. It would be nice if I could move the entire script to the top of the page and get it out of the way.

    Below is the source code for my query, the colors script and the table. Thanks.

    PHP Code:

    $res = mysql_query("SELECT Area, Class, `Order`, OrderCommon FROM symbols 
    WHERE Class = '$myname' ORDER BY `Order`");

    $groups = array();
    while ($row = mysql_fetch_assoc($res)) {
        $groups[$row['Order']][] = $row['Area'];
    }




    // TABLE CELL COLOR SCRIPT...

        $cset_size = sizeof($color_sets);
        
        $i = 0;
        while ($row = mysql_fetch_array ($res)) {
            // Determine color set
            $c = $i % $cset_size;

    // PROBLEM BRACKET
    }



    ?>
    <table>
    <tr><th>1</th><th>2</th></tr>


      <?php foreach ($groups as $class => $areas) { ?>
        <tr>
          <td class = "tdname" style="background-color: <?php $color_sets[$c][0?>">
            <?php echo htmlspecialchars(implode(', '$areas)); ?>
          </td>
          <td class = "tdsymbol" style="background-color: <?php $color_sets[$c][1?>">
            <?php echo htmlspecialchars($class); ?>
          </td>
        </tr>
      <?php ?>


    </table>

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another idea occurred to me...

    Would it be possible to alternate table row CLASSES, like this?:

    <tr class="1">
    <td class="name">
    <td class="symbol">
    <tr class="2">
    <td class="name">
    <td class="symbol">
    <tr class="3">
    <td class="name">
    <td class="symbol">

    If so, then I could color the cells with a style sheet, like this:

    tr.1 td.name { background: #fffff0; }
    tr.1 td.symbol { background: #ccf; }

    In fact, that might be a better solution, because it would also produce less html, right?


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
  •