I've been searching for this for about 2 hours and haven't found anything that specifically matches what I'm trying to do. It might not be possible, but I consider myself basic with php.
I have a php script that runs a MySQL query and uses that data to create an HTML email. The result is put into a while loop used to iterate and create HTML table rows for the n result rows. My primary goal is to use a separate array outside of the MySQL result array that contains an alternating bgcolor for each row, and put a function inside the MySQL result array that alternates between n colors that I choose. I am completely open to other solutions to make this use as little lines of code as possible.
Here is what the incomplete nonworking code basically looks like (using fake color names for readability):
$shade = array("red","blue","green");
$sql1 = "MySQL Query";
$sql1Handle = MySqlQuery($sql1,$DBLink);
while($sql1Data = mysql_fetch_row($sql1Handle))
{
$htmlText .= "<tr bgcolor = \"".$shade[0]."\"><td>".$sql1Data[0]."</td><td>".$sql1Data[1]."</td><td>".$sql1Data[2]."</td></tr>";
}
Expected colored result would be (if the MySQL result had 7 rows):
red row $sql1Data[0] $sql1Data[1] $sql1Data[2]
blue $sql1Data[0] $sql1Data[1] $sql1Data[2]
green $sql1Data[0] $sql1Data[1] $sql1Data[2]
red $sql1Data[0] $sql1Data[1] $sql1Data[2]
blue $sql1Data[0] $sql1Data[1] $sql1Data[2]
green $sql1Data[0] $sql1Data[1] $sql1Data[2]
red $sql1Data[0] $sql1Data[1] $sql1Data[2]
I know I can accomplish this task declaring two or more variables as colors and putting an if statement inside the while loop to alternate on each row, but I want to see if this is possible. I use it quite often and I'd prefer to create a function to handle this and provide it with however many colors I want.
Thanks.