title: Highlight table row in different colors based on values from database in php
body: <p>The code below has dynamic drop down list, that users chooses preferred brand and model, accordingly the table is generated in the webpage which results of brand, model and year . Now the code needs to group all the same year with different models and highlight them with set of different colors for each year accordingly. An expected results is attached as image.</p>
  
  <pre><code>// (___ &amp; !!!) or (ALL &amp; ___) or (ALL &amp; ALL)
  if ((!isset($_POST['model']) || ($_POST['brand'] == 'ALL' &amp;&amp; empty($_POST['model']))) || ($_POST['brand'] == 'ALL' &amp;&amp; $_POST['sip'] == 'ALL')) {
      $query1 = 'SELECT DISTINCT brand,model,year FROM `carlist` ORDER BY brand,model,year';
  }
  // (... &amp; ...) or (... &amp; ALL)
  else if (!empty($_POST['brand']) &amp;&amp; (empty($_POST['model']) || ($_POST['model'] == 'ALL'))) {
      $query1 = 'SELECT DISTINCT brand,model,year FROM `carlist` WHERE brand="'.$_POST['brand'].'" ORDER BY brand,model,year';
  }
  // (ALL &amp; ...) or (ALL &amp; notALL)
  else if ($_POST['brand'] == 'ALL' &amp;&amp; (!empty($_POST['model']) &amp;&amp; $_POST['model'] != 'ALL')) {
      $query1 = 'SELECT DISTINCT brand,model,year FROM `carlist` WHERE model="'.$_POST['model'].'" ORDER BY brand,model,year';
  }
  else {
      $query1 = 'SELECT DISTINCT brand,model,year FROM `carlist` WHERE brand="'.$_POST['brand'].'" AND model="'.$_POST['model'].'" ORDER BY brand,model,year';
  }
  //echo $_POST['brand'].'&lt;br /&gt;'.$_POST['model'];
  
  echo '&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;BRAND&lt;/th&gt;&lt;th&gt;MODEL&lt;/th&gt;&lt;th&gt;YEAR&lt;/th&gt;&lt;/tr&gt;';
  $result1 = mysqli_query($con, $query1);
  
  
      while($row1 = mysqli_fetch_array($result1)){
      //echo'&lt;tr&gt;&lt;td&gt;'.$row1['brand'].'&lt;/td&gt;&lt;td&gt;'.$row1['model'].'&lt;/td&gt;&lt;td&gt;'.$row1['year'].'&lt;/td&gt;&lt;/tr&gt;';
  
          $query2= 'SELECT DISTINCT brand,model,year, count(*) `number` FROM `carlist` WHERE brand="'.$_POST['brand'].'" GROUP BY `year` HAVING count(*) &gt; 1';
          $result2= mysqli_query($con, $query2);
          $count=0;
  
  
          while($row2 = mysqli_fetch_array($result2)){
  
              if ( $row2['year'] == $row1['year']) {
              $count=1;
              }
  
              //$intersect = array_intersect($row1,$row2);
              //echo $intersect[1];
  
  
          }
  
          $bgcolor = "#FF8C00"; 
          if($count==1){
              echo '&lt;tr style="background-color: tomato;" &gt;&lt;td&gt;'.$row1['brand'].'&lt;/td&gt;&lt;td&gt;'.$row1['model'].'&lt;/td&gt;&lt;td&gt;'.$row1['year'].'&lt;/td&gt;&lt;/tr&gt;';
  
          }else {
  
              echo'&lt;tr&gt;&lt;td&gt;'.$row1['brand'].'&lt;/td&gt;&lt;td&gt;'.$row1['model'].'&lt;/td&gt;&lt;td&gt;'.$row1['year'].'&lt;/td&gt;&lt;/tr&gt;';
          } 
  
      }
  
  
  echo '&lt;/table&gt;';
  </code></pre>