How to give alternating table rows different background colors using PHP -


I have a table of data that is dynamically generated on the content stored in a mysql database.

How does this look like my code:

  & lt; Table range = "1" & gt; & Lt; TR & gt; & Lt; Th & gt; Name & lt; / Th & gt; & Lt; Th & gt; Details & lt; / Th & gt; & Lt; Th & gt; Url & lt; / Th & gt; & Lt; / TR & gt; & Lt ;? Php $ query = mysql_query ("Select * categories"); While ($ line = mysql_fetch_assoc ($ query)) {$ catName = $ line ['name']; $ CatDes = $ line ['description']; $ CatUrl = $ line ['url']; Echo "& lt; tr class = '' & gt;"; Echo "& lt; td> $ catName ;"; Echo "& lt; td> $ catDes & lt; / td & gt;"; Echo "& lt; td> $ catUrl & lt; / td & gt;"; Echo "& lt; / tr & gt;"; }? & Gt; & Lt; / Table & gt; If the table was stationary, now I will give one of the two styles in each of the 2 styles in the alternate table row in sequential order:  
 . WhiteBackground {background-color: #fff; } .grayBackground {background color: #ccc; }  

And that will be the end of that. However, table rows are dynamically generated, how can I get this?

  & lt;? Php $ x ++; $ Square = ($ x% 2 == 0)? 'Whitebackground': 'Grabak Ground'; Echo "& lt; tr class = '$ class' & gt;"; ? & Gt;  

It basically checks to see that $ x is divisible by 2. If it is, then it is also.

PS If you have not seen any other query in that style, then it is called Turner Operator.


Comments

Post a Comment

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -