douluo3256 2012-09-13 08:13
浏览 24
已采纳

斑马条纹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>";

展开全部

  • 写回答

3条回答 默认 最新

  • duanliexi1052 2012-09-13 08:16
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 二维码被拦截如何处理
  • ¥15 怎么解决LogIn.vue中多出来的div
  • ¥15 优博讯dt50巴枪怎么提取镜像
  • ¥30 在CodBlock上用c++语言运行
  • ¥15 求C6748 IIC EEPROM程序固化烧写算法
  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部