Would very much appreciate some suggestions on the following:
I have a string which is being read from a MySQL field.
The string is the contents of an excel spreadsheet but it contains simplified form of BB code, which I use a series of str_replace() to convert to an HTML table.
That part works OK
My roblem is that I need to alternate the BG color in the table and as I don't always know how many rows there wil be I can't hard code the colou.
I thought that if I used explode() to turn the string in to an array with each each value of the array being a row of the table and the contents of the table being echoed via a "for" loop which ran the color change script it would work ...... but no luck.
Following is a code snippet so that you see what I mean.
// I set the colour variables
$color1 = "#C5AE9E";
$color2 = "#D2C1B5";
$ $row_count = 0;
// here is the string that will become the HTML table
// this is just a rogh example of it
$string = "[Otitle] Starters [Ctitle]
[Odish] Garlic Bread [Cdish] [Oprice] 7.00 [Cprice]
[Odish] Bruschetta [Cdish] [Oprice] 7.50 [Cprice]
[Odish] Nico's Salad [Cdish] [Oprice] 9.00 [Cprice]";
// again just an example - this time of the str_replace() section
$string = str_replace("[Otitle]", "<tr bgcolor='colourMyRow'> <td><strong>", $string);
$string = str_replace("[Ctitle]", "</strong></td></tr> %^&*", $string);
// now to convert the string into an Array using the un needed "%^&*" text
$myArray = explode("%^&*", $string);
// here I count the total values in the Array and start the loop
$arrayCounted = sizeof($myArray);
// this should alternate my colours
$row_colour = ($row_count % 2) ? $color1 : $color2;
// this should assign the colour to each row in the table
$menuArray [$i] = str_replace("colourMyRow", "$row_colour", $menuArray[$i]);
// as I said before, everything but the colour change works