duanqiang2617 2013-06-21 17:14
浏览 43
已采纳

如何在PHP中向表行添加多个类? [关闭]

I'm trying to fix the code of someone else. Right now I'm working on a dynamicly created table and would like to add a different class to each 2nd row. As an example the background of the 1st 3rd and 5th row should be white and the background of the 2nd 4th and 6th row grey.

Can anyone tell me how to add such 2nd class to the code?

I wasn't sure if the code would be required for this question - this is the part with a table. In case that this is not enough please let me know since my php skills are not good I'm even not sure what is need to understand the problem. As mentioned it's not my code...

   $arr = array();
foreach ($them as $z => $e) {
  $_them[$e['id']] = $e;
  if (count($arr) < 50) {
    $res = mysql_query('SELECT COUNT(*) FROM `forum_comments` WHERE `id_them` = ' . $e['id'] . '');
    $row = mysql_fetch_row($res);
    $total = $row[0];

    $arr[$e['id']] = $total;
  } else {
    $res = mysql_query('SELECT COUNT(*) FROM `forum_comments` WHERE `id_them` = ' . $e['id'] . '');
    $row = mysql_fetch_row($res);
    $total = $row[0];

    if ($total > $this->tools->array_val_min($arr)) {
      $arr[$this->tools->array_key_min($arr)] = $total;
    }
  }
}

arsort($arr);
$arr = array_chunk($arr, 25, true);
if (!empty($_GET['p'])) {
  $num = (int) $_GET['p'];
  if ($num == 1) {
    $arr = $arr[0];
  }
  if ($num > 1) {
    $arr = $arr[1];
  }
}

$ret = '
        <table class="forum_table">
            <tr class="forum_table_title">
                <th id="them">' . l::themes() . '</th>
                <th id="date">' . l::added() . '</th>
                <th id="users">' . l::guests() . '</th>
                <th id="commets">' . l::answers() . '</th>
                <th id="last">' . l::last_comments() . '</th>
            </tr>
            <tr class="empty_td">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
    ';
  • 写回答

3条回答 默认 最新

  • doudao7511 2013-06-21 17:20
    关注

    Just use some css, it'll apply it automatically:

    .your_table tr:nth-child(odd) { background-color:#00000; }
    .your_table tr:nth-child(even) { background-color:#ffffff; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了