php - Style Certain Table Rows from Database Query Set Data with CSS -


i have set of data in mysql database. have table created these data using php loops. want style rows in ways. example, data fetched database in groups of 2, 3, 4, 5 rows. there 25 rows of data , i'd style each group bit differently, eg, add color row sub heading...

i built out , didn't quite take consideration styling necessary. client wants styling , i'm trying figure out how make it.

here image excel kind of thing i'm trying accomplish:

enter image description here

i hand write html , style code cleaner , tighter when using php loops. also, if can figure out, use model , template other scenarios need style parts of table more data.

here php snippet:

<table>     <tr>         <th>hd1</th>         <th>hd2</th>         <th>hd3</th>     </tr>      <?php      $mysqli = <connect db fine>;      $query = 'select a, b, c t1';      if($stmt = mysqli_prepare($mysqli, $query)) {         mysqli_stmt_execute($stmt);         mysqli_stmt_bind_result($stmt, $a, $b, $c);          while (mysqli_stmt_fetch($stmt)) {             echo '<tr>';             echo '<td>' . $a . '</td>';             echo '<td>' . $b . '</td>';             echo '<td>' . $c . '</td>';              echo '</tr>';                }     }      ?>  </table> 

in part of code add class sub-headings :

$subheadingscontent = array("a", "sub heading", "cell data");  while (mysqli_stmt_fetch($stmt)) {       if(in_array($a, $subheadingscontent)) echo '<tr class="subheading">';      echo '<td>' . $a . '</td>';     echo '<td>' . $b . '</td>';     echo '<td>' . $c . '</td>';      echo '</tr>';        } 

and add class in css file foreach element , first , second , third .... :

 .subheading:nth-child(1){background-color:blue;}  .subheading:nth-child(2){background-color:orange;}  .subheading:nth-child(3){background-color:gray;} 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -