Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:16:20+00:00 2026-05-27T12:16:20+00:00

I have a MySQL database with 35 different columns labeled 1-35. The data is

  • 0

I have a MySQL database with 35 different columns labeled 1-35. The data is displayed in a dynamic table. I am looking for the PHP code that would allow me to apply a CSS class to specific cells based on what is returned inside them.

EXAMPLE: Column 1 can return either TRUE or FALSE value. If a TRUE value is returned, I want to give that cell a different background color, or highlight it.

I have the CSS class as:

.highlight {
background-color: #FC0;
}

After the CSS class has then been applied to the specific cells from columns 1-35, I would like the PHP code that can total the number of highlighted cells in the column labeled TOTAL.

Can’t seem to find the PHP code to tie all this together. If someone could advise, I’d be very grateful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:16:21+00:00Added an answer on May 27, 2026 at 12:16 pm
    <td class="<?php if ($row['item'] == TRUE)
    {
        echo 'highlight';
        $highlights++;
    }
    else
    {
        echo 'no_highlight';
    }
    ?>"><?php echo $row['item'];?></td>
    

    and then…

    <td id="totalHighlights"><?php echo $highlights;?></td>
    

    EDIT: Sample code…

    <?php
    
    //We've queried the database and passed the results into $result via mysql_fetch_assoc().
    
    while ($row = $result)
    {
        //Clear highlights and values arrays for each row.
        $highlights = array();
        $values = array();
        foreach($row as $entry)
        {
            if ($entry == TRUE)
            {
                //Put a truthy value into highlights array.
                array_push($highlights, 1);
            }
            else
            {
                //Put a falsey value into highlights array.
                array_push($highlights, 0);
            }
    
            //Push actual field value to values array.
            array_push($values, $entry);
        }
        echo '<tr class="row">';
    
        //Create cell with total highlights per row using the array_sum() of highlights.
        echo '<td class="row_total_highlights">'.array_sum($highlights).'</td>';
    
        //Create each value cell and populate them with each field value from values array.
        $i = 0;
        foreach ($values as $value)
        {
            echo '<td class="entry ';
            echo ($highlights[$i] == 1 ? 'trueClass' : 'falseClass');
            echo '">'.$value.'</td>';
            $i++;
        }
        echo '</tr>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database table with two columns that interest me. Individually they
I have a script that grabs data from a MySQL database table and creates
I have a website that has approx 1000 different strings in a mysql database
When I have two mysql servers that have different jobs (holding different databases) but
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a MySQL database table with a couple thousand rows. The table is
I have a MySQL database of keywords that are presently mixed-case. However, I want
I have a MySQL database that I want to archive . What is the
I have a MySQL database with two tables (simplified for this question): movies table
I'm trying to validate a pair of data columns on mysql from my php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.