Use static to display the color of a table in different rows
We use PHP to query data from the database and output the results to the browser. If there are many rows in the results and the bgcolor of the table is all monochrome, the browser will feel uncomfortable. So how can we make the color of each row of the table different?
See the following:
<?
Function getcolor ()
{
Static $ colorvalue; // defines a static variable.
If ($ colorvalue = "# ffffff ")
$ Colorvalue = "#000000 ";
Else $ colorvalue = "# ffffff ";
Return ($ colorvalue );
}
Print ("<Table border = 1> N"); // output 10 rows below
For ($ I = 0; $ I <10; $ I ++)
{$ Bcolor = getcolor (); // change the background color
Print ("<tr bgcolor = $ bcolor> N ");
Print ("<TD> $ I </TD> N ");
Print ("</tr> ");
}
Print ("</table> N ");
Note:
ThisProgramStatic $ colorvalue is defined in,
The variable $ colorvalue is retained and does not disappear. When the getcolor () function is called again, the value of the variable $ colorvalue is the value of $ colorvalue at the end of the last function call.