I am attempting to echo a sting containing a variable already stored in a variable. Essentially I am building a class that can dynamically build tables based on a changing number of columns. I need get my db field names into the foreach loop before the foreach loop that has my db results, and then iterate over them in the loop. The problem is I have to store them in a loop prior to the db results loop; which is not recognizing it as a variable and just giving me a plain text '$row['myVar']'.
How can I get this to recognize the variable in the second loop?
$sqlVarNames = explode(', ', $sqlVar);
foreach ($sqlVarNames as $columnVar) {
$finalColumnVars .= '<td>\'. $row[\''.$columnVar.'\'] .\'</td>';
}
and then into my second loop
foreach ($sqlResult as $row) {
echo '<tr>';
echo $finalColumnVars;
echo '</tr>';
}
I tried all sorts of escape sequences on my $finalColumnVars and can't seem to get it to output the variable instead on plain text.
Here is what I get with the above code
<td>'. $row['client_name'] .'</td>
Is this possible?