2017-02-17 14 views
0

CSSの奇数行(#e5e8e8)と偶数行(#b9b8bb)のそれぞれに背景色を追加します。PHPでODD行とEVEN行の背景色を追加するには?

for ($i = 2; $i <= $arrayCount; $i++) { 

     $_SESSION["a"] = trim($allDataInSheet[$i]["A"]); 

     $_SESSION["b"] = trim($allDataInSheet[$i]["B"]); 

     $_SESSION["c"] = trim($allDataInSheet[$i]["C"]); 

     $_SESSION["d"] = trim($allDataInSheet[$i]["D"]); 

     $_SESSION["e"] = trim($allDataInSheet[$i]["E"]); 

     $_SESSION["f"] = trim($allDataInSheet[$i]["F"]); 

     $_SESSION["g"] = trim($allDataInSheet[$i]["G"]); 


         echo '<!-- table content - start --> '; 
         echo ' <!-- ROW 1 -->'; 
         echo '<tr>'; 
          echo '<td width="10" style="border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo ' </td>'; 

          echo '<td width="164" style="border-bottom: 1px solid #ffffff;" valign="middle">'; 
           echo '<table width="164" border="0" cellspacing="0" cellpadding="0">'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo ' </tr>'; 
            echo '<tr>'; 

             echo '<td width="114" valign="middle" align="left">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 

               echo $_SESSION["a"]; 
              echo '</font>'; 
             echo ' </td>'; 

             echo ' <td width="50" valign="middle" align="right">'; 

             echo '</td>'; 
            echo '</tr>'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo ' </tr>'; 
           echo '</table>'; 
          echo '</td>'; 

          echo ' <td width="10" style="border-right: 1px solid #ffffff;border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 
          echo '<td width="10" style="border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 
          echo '<td width="164" style="border-bottom: 1px solid #ffffff;" valign="middle">'; 
           echo '<table width="164" border="0" cellspacing="0" cellpadding="0">'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo ' </tr>'; 
            echo '<tr>'; 
             echo '<td width="114" valign="middle" align="left">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
               echo $_SESSION["b"]; 

              echo '</font>'; 
             echo '</td>'; 
             echo '<td width="50" valign="middle" align="right">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
               echo $_SESSION["c"]; 
              echo '</font>'; 
             echo '</td>'; 
            echo ' </tr>'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo '</tr>'; 
           echo '</table>'; 
          echo '</td>'; 
          echo '<td width="10" style="border-right: 1px solid #ffffff;border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 
          echo '<td width="10" style="border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 
          echo '<td width="164" style="border-bottom: 1px solid #ffffff;" valign="middle">'; 
           echo '<table width="164" border="0" cellspacing="0" cellpadding="0">'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo ' </tr>'; 
            echo '<tr>'; 
             echo '<td width="114" valign="middle" align="left">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
              echo $_SESSION["d"]; 

              echo '</font>'; 
             echo '</td>'; 
             echo '<td width="50" valign="middle" align="right">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
              echo $_SESSION["e"]; 
              echo '</font>'; 
             echo '</td>'; 
            echo '</tr>'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo '</tr>'; 
           echo '</table>'; 
          echo '</td>'; 
          echo '<td width="10" style="border-right: 1px solid #ffffff;border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 

          echo '<td width="10" style="border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 
          echo '<td width="164" style="border-bottom: 1px solid #ffffff;" valign="middle">'; 
           echo '<table width="164" border="0" cellspacing="0" cellpadding="0">'; 
            echo '<tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo '</tr>'; 
            echo '<tr>'; 
             echo '<td width="114" valign="middle" align="left">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
              echo $_SESSION["f"]; 

              echo '</font>'; 
             echo ' </td>'; 
             echo '<td width="50" valign="middle" align="right">'; 
              echo '<font style="font-family: HP Simplified, arial, sans-serif; font-size:15px;color:#000000;font-weight:normal; line-height:16px;">'; 
               echo $_SESSION["g"]; 
              echo ' </font>'; 
             echo '</td>'; 
            echo ' </tr>'; 
            echo ' <tr>'; 
             echo '<td height="15" style="font-size:0px;line-height:0px;"><img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="1" height="15" style="display:block;border:none;"/></td>'; 
            echo ' </tr>'; 
           echo '</table>'; 
          echo ' </td>'; 
          echo '<td width="10" style="border-bottom: 1px solid #ffffff;">'; 
           echo '<img src="http://ebiz.pmgasia.com/web/hp/HP_ProTrain_Monthly_eDM/ID/2017/February/images/x.gif" width="10" height="1" style="display:block;border:none;"/>'; 
          echo '</td>'; 

         echo '</tr>'; 

         echo '<!-- ROW 1 - END -->'; 


    } 

ここに私が動的loop.Myための指定されたテーブル上のコードが作成された内部Iが書いたこの行にPHPの各奇数行(#e5e8e8)と偶数行(#1 b9b8bb)の背景色を追加しますメールテンプレートのために。それは多くのs.so ODDとEVENオプションが正常に動作していません。任意の提案。事前にお礼します。

+0

あなたのコードがあります:ここでは例ですか? – Option

+0

私はちょうど私のポストを編集しました。事前に助けてください。おめでとうございます –

+0

クリキー!なぜそんなに多くのエコー? – Option

答えて

1

あなたのコードを掘り下げて修正する必要はありません。現実的には..これを行うにはnth-child()を使用する必要があります。

tr:nth-child(odd) \t \t { background-color:#e5e8e8; } 
 
tr:nth-child(even) \t \t { background-color:#b9b8bb; }
<table> 
 
    <tr> 
 
     <td> Row 1</td> 
 
    </tr> 
 
    <tr> 
 
     <td> 
 
      Row 2 
 
     </td> 
 
    </tr> 
 
</table>

+0

PHPの内部で次のコードを使用する方法:tr:nth-​​child(odd)\t \t {background -color:#e5e8e8; } tr:nth-​​child(偶数)\t \t {背景色:#b9b8bb; } –

+0

上記のテーブルコードがメールテンプレート用に作成されました。と​​s.so ODDとEVENオプションが正しく機能していません。何か提案があります。事前にお待ちしております –

+0

ご協力ありがとうございます。 –

関連する問題