斑马条纹PHP MYSQL表 [英] Zebra Stripe PHP MYSQL Table
本文介绍了斑马条纹PHP MYSQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想斑马条纹结果表.我找不到可靠的解决方案.我需要对这个表做些什么,以将一个奇/偶类添加到结果行?
I would like to Zebra Stripe the results table. I can't find a solid solution. What would I need to do to this table to add a odd/even class to the results rows?
// HTML ... Aliases from Mysql
echo "<table class='sortable' id='tablesorter' cellspacing='1' cellpadding='0' border='0' width='920px' >
<thead>
<tr>
<th class='header'>Short Name of Fund</th>
<th class='header'>I/C</th>
<th class='header'>Fund Manager Company</th>
<th class='header'>Class</th>
<th class='header'>Special Class</th>
<th class='header' id='custom'>TTR year-to-date<br /> %</th>
<th class='header'>Mgmt Fee Effectively Charged</th>
<th class='header id='custom'>Total Expenses <br /> %</th>
<th class='header'>Fund Size</th>
</thead><tbody>
</tr>";
//<tr> specifies table row. for each <td> (table data) will specify a new column. The $row specifies the mysql column name (in this case using an alias)
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><a href=\"page.php?id={$row['ID']}\">{$row['Short Name of Fund']}</a></td>";
echo "<td>" . $row['I/C'] . "</td>";
echo "<td>" . $row['Fund Manager Company'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "<td>" . $row['Special Class'] . "</td>";
echo "<td>" . $row['TTR year-to-date %'] . "</td>";
echo "<td>" . $row['Mgmt Fee Effectively Charged'] . "</td>";
echo "<td>" . $row['Total Expenses %'] . "</td>";
echo "<td>" . $row['Fund Size'] . "</td>";
echo "</tr>";
}
echo "</tbody></table>";
推荐答案
这应该有效,语法可能不正确,因为我尚未对其进行测试.但是逻辑就在那里.
This should work, the syntax may be incorrect as I have not tested it. But the logic is there.
$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;
编辑:已更新代码,因此可以正常工作.
EDIT: Updated code so it works.
这篇关于斑马条纹PHP MYSQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文