This tutorial will show you how you can display each line from an array using different styles: font, background color, text color etc.. The idea is to have a .css file containing different class for each style we want. Then in a loop we can give to
Let’s take an example and explain it :
You need to define your styles (two or more) in a .css file or in the head of your html page.
Ok, now the PHP code:
// an array with the two styles that we want to alternate
$css_clas = array(‘class1’, ‘class2’);
$nr_clas = count($css_clas); //counts the nr. of styles that we want to alternate
$i_clas = 0; // this will be used for alternate the two styles.
// we are going on $aray array to display the data.
// HTML code for creating the tables
$html_table = ‘
|‘. $i. ‘||‘. $aray[$i]. ‘||‘. $aray[$i]. ‘|
‘; // we close the html table
echo $html_table; // we display the table
That’s it! You can do it also with a FOR loop.
The code is very well explained, but if you have questions please ask .
Thank you for reading and I hope you enjoy reading this PHP tutorial that shows you how to alternate CSS styles when displaying data.
Leave a Reply