php - give color to specific row of a table acc. to situation -


i created table database column name "do have passport" user answers in yes or no want user answer yes row should green , row user answer no row white can 1 tell me how can apply css table works dynamically.

<html> <head> <style> table, th, td {     border: 1px solid black;     border-collapse: collapse; } </style> </head> </html> <?php      $conn = new mysqli("localhost","root","","db_dat");     $havepassport='';     $sql="select * upload;     $result = $conn->query($sql);     while($row = $result->fetch_assoc()) {         $havepassport.='<table>'.'<tr>'.'<td>';         $havepassport.=$row['having_passport'];         $havepassport.='</table>'.'</tr>'.'</td>';         echo $havepassport;     } ?> 

you doing wrong. while add new table html. so, if have 100 rows, 100 tables added dom instead of rows.

use following:

php

$sql = "select * upload"; $result = $conn -> query($sql);  $havepassport = '<table>'; while ($row = $result -> fetch_assoc()) {     $passportclass = $row['having_passport'] == 'yes' ? 'green' : 'red';     // ^^^^^^^^^^^ getting classname depending on passport value      $havepassport .= '<tr class='.$passportclass.'>'.     //                            ^^^^^^^^^^^^^^  add class here             '<td>';                 $havepassport. = $row['having_passport'];     $havepassport .= '</td>'.         '</tr>';  } $havepassport .= '</table>'; echo $havepassport; 

css:

.green {     background: green; } .red {     background: red; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -