So I'm trying to apply some of the lessons in the book to a real world application so I am trying to apply the ternary operator just like it was used in the book but in a more complicated script. Here is the script and it isn't working. I think I might have a syntax issue but I can't figure it out. Any ideas?
// Start result table printed to browser
if ($_GET['rep1'] == TRUE) {
$numberFields = mysql_num_fields($q); // Find out how many fields we are fetching
if($numberFields) { // Check if we need to output anything
for($i=0; $i<$numberFields; $i++) {
$keys[] = mysql_field_name($q, $i); // Create array of the names for the loop of data below
$head[] = (mysql_field_name($q, $i)); // Create the headers for each column, this is the field name in the database
}
$headers = join('</td><td>', $head)."\n"; // Make our first row in the CSV
$data = '';
while($info = mysql_fetch_object($q)) {
foreach($keys as $fieldName) { // Loop through the array of headers as we fetch the data
$row[] = (trim($info->$fieldName));
} // End loop
$data .= join('</td><td>', $row)."</td></tr>\n<tr bgcolor=\"'.$bg.'\"><td>"; // Create a new row of data and append it to the last row (this line is where I'm having the problem)
$row = ''; // Clear the contents of the $row variable to start a new row
}
// Output our report
$bg = '#eeeeee'; //Set the initial background color.
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //Switch the background color.
echo
'<table>
<tr bgcolor="' . $bg . '">
<td>' . $headers . '</td>
</tr>
<tr bgcolor="' . $bg . '">
<td>' . $data . '</td>
</tr>
</table>';
}
}