user2178637
user2178637

Reputation: 117

applying stylesheet class for dynamic rows

I am trying to apply css class for dynamic rows in php. But its not happening. Here is my code please someone suggest me where i am going wrong. I have declared a counter for rows but not getting where to increment its count.

 <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>

Upvotes: 0

Views: 86

Answers (3)

Abela
Abela

Reputation: 1233

Three issues with your code (four if you count the fact that you have a massive amount of HTML that should be moved outside of being echo'ed within php)

1) You have no $k++; to increment your $k value

2) You have a "tr" within the $row['name'] line that needs to be removed.

3) You need to move the entire if($k) block INSIDE of your while() loop.

Upvotes: 0

RDK
RDK

Reputation: 4560

If you want decorate your table, and you can use css use it. Don't use server side language

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

Upvotes: 1

Jhonathan H.
Jhonathan H.

Reputation: 2713

Try to put this inside your while loop.

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

Upvotes: 1

Related Questions