douliaodun9153 2015-06-13 19:04
浏览 36
已采纳

too long

My friend made new design for my table but i couldnt integrate old table php code to the new design. How can i make it? Thanks

This is my old table;

<table align="center" width="1200" height="370" cellpadding="7">
              <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Sex</th>
                <th>Country</th>
                <th>Age</th>
                <th>Twitter</th>
                <th>Instagram</th>
                <th>Snapchat</th>
                <th>Details</th>
            </tr>

            <?php
            foreach($db->query('SELECT * FROM uyeler ORDER BY RAND()LIMIT 20') as $row) {
                    echo "<tr><td>" .$row['id'] . "</td>";
                    echo "<td>" .$row['fname'] . "</td>";
                    echo "<td>" .$row['sex'] . "</td>";
                    echo "<td>" .$row['country'] . "</td>";
                    echo "<td>" .$row['age'] . "</td>";
                    echo "<td>" .$row['twitter'] . "</td>";
                    echo "<td>" .$row['instagram'] . "</td>";
                    echo "<td>" .$row['snapchat'] . "</td>";
                    echo ('<td><a href="details.php?id=' .$row['id'] . '" title="Panel">Details</a></td>');
                    echo "</tr>";
                }
            ?>

            </table>

This is new design, (One line dark, one line black....)

<table class="table table-striped">

                                <!--Table Header -->
                                    <tr>
                                        <th class="t_head">ID</th>
                                        <th class="t_head">NAME</th>
                                        <th class="t_head">SEX</th>
                                        <th class="t_head">COUNTRY</th>
                                        <th class="t_head">AGE</th>
                                        <th class="t_head">TWITTER</th>
                                        <th class="t_head">INSTERGRAM</th>
                                        <th class="t_head">SNAPCHAT</th>
                                        <th class="t_head">DETAILS</th>
                                    </tr>

                                <!--Row 01 -->  
                                    <tr class="t_light">
                                        <td>14</td>
                                        <td>Taha</td>
                                        <td>Male</td>
                                        <td>Russia</td>
                                        <td>2000</td>
                                        <td>Tahains</td>
                                        <td>Male</td>
                                        <td>Male</td>
                                        <td><a href="#">Details</a></td>
                                    </tr>

                                <!--Row 02 -->  
                                    <tr class="t_dark">
                                        <td>14</td>
                                        <td>Taha</td>
                                        <td>Male</td>
                                        <td>Russia</td>
                                        <td>2000</td>
                                        <td>Tahains</td>
                                        <td>Male</td>
                                        <td>Male</td>
                                        <td><a href="#">Details</a></td>
                                    </tr>

                                <!--Row 03 -->  
                                    <tr class="t_light">
                                        <td>14</td>
                                        <td>Taha</td>
                                        <td>Male</td>
                                        <td>Russia</td>
                                        <td>2000</td>
                                        <td>Tahains</td>
                                        <td>Male</td>
                                        <td>Male</td>
                                        <td><a href="#">Details</a></td>
                                    </tr>

                                <!--Row 04 -->  
                                    <tr class="t_dark">
                                        <td>14</td>
                                        <td>Taha</td>
                                        <td>Male</td>
                                        <td>Russia</td>
                                        <td>2000</td>
                                        <td>Tahains</td>
                                        <td>Male</td>
                                        <td>Male</td>
                                        <td><a href="#">Details</a></td>
                                    </tr>

                                <!--Row 05 -->  
                                    <tr class="t_light">
                                        <td>14</td>
                                        <td>Taha</td>
                                        <td>Male</td>
                                        <td>Russia</td>
                                        <td>2000</td>
                                        <td>Tahains</td>
                                        <td>Male</td>
                                        <td>Male</td>
                                        <td><a href="#">Details</a></td>
                                    </tr>

                                </table>

A part of css file;

.table-striped>tbody>tr:nth-child(odd)>td, .table-striped>tbody>tr:nth-child(odd)>th
{
    background: #e0dfdf;
}

.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td
{
    background: #f7f7f7;
}
  • 写回答

2条回答 默认 最新

  • douqin6785 2015-06-13 19:10
    关注

    You can do it as follows

    <table align="center" width="1200" height="370" cellpadding="7">
        <tr>
            <th class="t_head">ID</th>
            <th class="t_head">NAME</th>
            <th class="t_head">SEX</th>
            <th class="t_head">COUNTRY</th>
            <th class="t_head">AGE</th>
            <th class="t_head">TWITTER</th>
            <th class="t_head">INSTERGRAM</th>
            <th class="t_head">SNAPCHAT</th>
            <th class="t_head">DETAILS</th>
        </tr>
        <?php
        $i=1;
        foreach($db->query('SELECT * FROM uyeler ORDER BY RAND()LIMIT 20') as $row) {
            if ($i%2!=0)
                $class="t_light";
            else
                $class="t_dark";
            echo "<tr class='".$class."'><td>" .$row['id'] . "</td>";
            echo "<td>" .$row['fname'] . "</td>";
            echo "<td>" .$row['sex'] . "</td>";
            echo "<td>" .$row['country'] . "</td>";
            echo "<td>" .$row['age'] . "</td>";
            echo "<td>" .$row['twitter'] . "</td>";
            echo "<td>" .$row['instagram'] . "</td>";
            echo "<td>" .$row['snapchat'] . "</td>";
            echo ('<td><a href="details.php?id=' .$row['id'] . '" title="Panel">Details</a></td>');
            echo "</tr>";
            $i++;
        }
        ?>
    </table>
    

    What I have done is that, inside the for each loop I checks whether each of the iteration is wwhether odd or even and applies the class appropriately.

    I think, you are using such a code to style alternate rows differently. This can be done with CSS selectors. No need for adding separate classes for rach rows.

    In pure CSS you can do the following:

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集