为动态行应用样式表类

时间:2013-04-04 06:05:57

标签: php css

我正在尝试在php中为动态行应用css类。但它没有发生。这是我的代码 请有人建议我哪里出错了。我已经为行声明了一个计数器但没有得到增加计数的位置。

 <table width='100%' border='0' cellspacing='0' cellpadding='2'>
          <tr>
            <td class='tddash'>10 latest unpaid customer invoices</td>
          </tr>
          <tr>
            <td valign='top'>";

            $SQL = "SELECT salesorders.orderno,
                        debtorsmaster.name,
                        custbranch.brname,
                        salesorders.customerref,
                        salesorders.orddate,
                        salesorders.deliverydate,
                        salesorders.deliverto,
                        salesorders.printedpackingslip,
                        salesorders.poplaced,
                        SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)/currencies.rate) AS ordervalue
                    FROM salesorders INNER JOIN salesorderdetails
                        ON salesorders.orderno = salesorderdetails.orderno
                        INNER JOIN debtorsmaster
                        ON salesorders.debtorno = debtorsmaster.debtorno
                        INNER JOIN custbranch
                        ON debtorsmaster.debtorno = custbranch.debtorno
                        AND salesorders.branchcode = custbranch.branchcode
                        INNER JOIN currencies
                        ON debtorsmaster.currcode = currencies.currabrev
                    WHERE salesorderdetails.completed=0
                    GROUP BY salesorders.orderno,
                        debtorsmaster.name,
                        custbranch.brname,
                        salesorders.customerref,
                        salesorders.orddate,
                        salesorders.deliverydate,
                        salesorders.deliverto,
                        salesorders.printedpackingslip,
                        salesorders.poplaced
                    ORDER BY salesorders.orderno";
                    $SalesOrdersResult1 = DB_query($SQL,$db);


                    echo "<table width='100%' celpadding='2' class='selection'><tbody>";
                            $TableHeader = "<tr><th> Customer </th><th>Order Date</th><th>Delivery Date</th><th>Delivery To</th><th>Order Total</th></tr> ";

                            $k = 0;





                    while ($row = DB_fetch_array($SalesOrdersResult1))

                        {

if ($k == 1){
                echo '<tr class="EvenTableRows">';
                $k = 0;
            } else {
                echo '<tr class="OddTableRows">';
                $k = 1;
            }
                            $FormatedOrderValue1 = locale_number_format($row['ordervalue'],$row['currdecimalplaces']);
                            //$TotalOrderValue = $array_sum($FormatedOrderValue1);
                            //$FormatedOrderValue1 = locale_number_format($myrow['ordervalue'],$_SESSION['CompanyRecord']['decimalplaces']);
                            $FormatedOrderDate = ConvertSQLDate($row['orddate']);
                            $FormatedDelDate = ConvertSQLDate($row['deliverydate']);

                            echo " <td> " . $row['name'] . " </td>";
                            echo " <td>$FormatedOrderDate</td><td>$FormatedDelDate</td><td> " . $row['deliverto'] . " </td><td>$FormatedOrderValue1</td> ";

            }
                        //echo "<tr><td colspan='3'>Total</td><td colspan='2'>$TotalOrderValue</td></tr></tbody>";
                        //echo $array_sum($FormatedOrderValue1);
            echo "</table>";

            echo"</td>
          </tr>
        </table>

3 个答案:

答案 0 :(得分:1)

尝试将其放入while循环中。

if ($k == 1){
            echo '<tr class="EvenTableRows">';
            $k = 0;
        } else {
            echo '<tr class="OddTableRows">';
            $k = 1;
        }

答案 1 :(得分:1)

如果你想装饰你的桌子,你可以用css使用它。不要使用服务器端语言

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

答案 2 :(得分:0)

您的代码存在三个问题(如果您认为自己有大量的HTML应该移到php中回显之外的事实,则会有四个问题)

1)你没有$ k ++;增加你的$ k值

2)$ row ['name']行中有一个“tr”需要删除。

3)你需要移动while()循环的整个if($ k)块。