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

  • SEARCH
  • Home
  • 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 3305616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:11:25+00:00 2026-05-17T21:11:25+00:00

The code below echoes out an HTML table, populated with values from a MySQL

  • 0

The code below echoes out an HTML table, populated with values from a MySQL database. The CSS changes when a field called “topten” equals 1.

When “topten” equals 1, I would like to have a rectangular background 100 pixels high, 800 pixels wide, and color #A6FFFF;. When “topten” does not equal 1, I would like there to be no background. I would imagine that I could do this by applying some CSS where there is “backgroundtt” below. How can I do this?

$result = mysql_query($sqlStr);

$arr = array(); 
echo "<table class=\"samplesrec\">";
while ($row = mysql_fetch_array($result)) {         
  if($row["topten"] == 1) {    
     echo '<div class="backgroundtt"></div>';
     echo '<tr class="class2a">';
     echo '<td class="sitename1"></td>';
     echo '</tr>';
     echo '<tr class="class2b">';
     echo '<td class="sitename2name"></td>';
     echo '</tr>';
     echo '<tr class="class2c">';
     echo '<td class="sitename2"></td>';
     echo '</tr>';
  } else {      
    echo '<tr class="class3a">';
    echo '<td class="sitename1"></td>';
    echo '</tr>';
    echo '<tr class="class3b">';
    echo '<td class="sitename2name"></td>';
    echo '</tr>';
    echo '<tr class="class3c">';
    echo '<td class="sitename2"></td>';
    echo '</tr>';
  }
}

echo "</table>";
  • 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-17T21:11:26+00:00Added an answer on May 17, 2026 at 9:11 pm

    It is not valid markup to have a div inside of a table that is not in an actual table cell. What you will want to do instead is apply a class to the three rows that are in the topten call so that section might look like this:

     if($row["topten"] == 1) {    
     echo '<tr class="class2a coolBackgroundClass">';
     echo '<td class="sitename1"></td>';
     echo '</tr>';
     echo '<tr class="class2b coolBackgroundClass">';
     echo '<td class="sitename2name"></td>';
     echo '</tr>';
     echo '<tr class="class2c coolBackgroundClass">';
     echo '<td class="sitename2"></td>';
     echo '</tr>';
     }
    

    Then you can set the background color like so in css:

    .coolBackgroundClass { background-color: #A6FFFF; }
    

    So instead of trying to absolutely position a div behind those rows (which in its placement is invalid markup) you just set the background color of each of the three rows so it looks like on large rectangular box. Also if your rows grow in size the box will grow with them.

    Edited: missed a semicolon in css markup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: I have provided complete code example in answer below. I have built my
All the code below works. My device responds, C,7 is a reset. When I
I have four search fields that are used to search a database for book
I have a small script which im using to test PHP mail(), as below:
I have set my database fields username and email to unquie, when using the
I have a function which checks the passed value and returns false or true,
I have been tearing my hair with this one for a while. index.php: $(document).ready(function(){
I'm stumped. Why would a query work in phpMyAdmin but not in a MAMP
I have created a category template in Wordpress for all posts that are in
I have tried for three days now and gotten nowhere on this.... I absolutely

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.