SQL >> Base de Datos >  >> RDS >> Mysql

Crear una tabla PHP MySQL con filas alternadas (zebra)

Esto debería funcionar; la sintaxis puede estar ligeramente mal porque no lo he probado, pero la lógica es sólida.

$currentState = 'odd'; $html = ''; while($row = mysql_fetch_array($result)){ $currentState = ($currentState == 'odd' ? 'even' : 'odd'); $html .= '<tr class="'.$currentState.'">'; $html .= '<td><a href="page.php?id=' . $row['ID'] . '">'. $row['Short Name of Fund'] .'</a></td>'; $html .= '<td>' . $row['I/C'] . '</td>'; $html .= '<td>' . $row['Fund Manager Company'] . '</td>'; $html .= '<td>' . $row['Class'] . '</td>'; $html .= '<td>' . $row['Special Class'] . '</td>'; $html .= '<td>' . $row['TTR year-to-date %'] . '</td>'; $html .= '<td>' . $row['Mgmt Fee Effectively Charged'] . '</td>'; $html .= '<td>' . $row['Total Expenses %'] . '</td>'; $html .= '<td>' . $row['Fund Size'] . '</td>'; $html .= '</tr>'; } echo $html; 

EDICIÓN: Actualicé el código para que funcione.

Nota: mysql_fetch_array está obsoleta y eliminada en PHP 7; usa mysqli o PDO. Además, escapa siempre la salida con htmlspecialchars() para evitar XSS.