English 中文(简体)
PHP 与此同时,甚至还剩下单行。
原标题:PHP while loop, even/odd rows returned

我有一张PHP涡轮机,显示我网站上特定张贴的数据。 我想要做的是,为退还的行数,积极分配哪怕是/为什么要分配哪类。 例如,

first row returned - odd class
second row returned - even class
third row - odd class

这将使我能够分配不同的背景图,使数据能够直观地分开。

我应当澄清——这一数据没有在表格中填报。

 while ($row = mysql_fetch_assoc($result)) {

    echo "
    <div class="songContainer" id="" . $row[ trackid ] . "">
最佳回答

视你们的行凶对象而定,你可以与社会保障局一道这样做:

.mytable tr:nth-child(even) { background-color: #FFF; }
.mytable tr:nth-child(odd) { background-color: #EEE; }

http://www.quirksmode.org/css/nthchild.html

如果你确实需要PHP,则使用模块:

$i = 0;
foreach ($arr as $val) {
    if (0 == $i % 2) {
        // even
    }
    else {
        // odd
    }
    $i++;
}
问题回答

小学三年级学生会得到同样的支持。

table tr:nth-child(even) td{

}

table tr:nth-child(odd) td{

}

但是,如果你再支持老年人,那么你别无选择,只能由私人住房项目生成集体名称。

$num_rows = 0;
$current_class = "";
while ($row = mysql_fetch_array($result)){
    $current_class = "class_odd";
    if($num_rows % 2 == 0){
        $current_class = "class_even";
    }

    $num_rows++;
}

Use this jQuery:

$("tr:nth-child(2n)").addClass("even")
  .prev().addClass("odd");

It selects every second tr element and adds an even class to it. Then it selects the previous tr element and adds an odd class to it.

Example。

在使用营地时,你可以使用,而不是帕斯卡尔建议的模块:

    $i = 0;
    foreach ($arr as $val) {
        if ( $i = 1 - $i ) {
            // even
        }
        else {
            // odd
        }
    }




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签