KJS KJS - 4 months ago 30
MySQL Question

Auto generate mysqli_fetch_array column results

I am trying to auto-generate the mysqli_fetch_array column results, like:


The values are stored in array '$lang_news_cols_arr', used as:

foreach($lang_news_cols_arr as $lang_news_col_name) {
$news_rows .= '$'.$lang_news_col.'=$rows["'.$lang_news_col.'"];';

$news_rows would then have the following result:


And finally be used as:

while ($rows = mysqli_fetch_array ($query) ) {

I can't get the values to the $news_rows in the fetch array. Any help is very appreciated.


$news_rows is a string variable, php will not execute its contents as code without being explicitly instructed to do so. You could technically do this by calling the eval() function, but you really should not do this, since it introduces a huge security risk. eval() can execute any arbitrary php code, thus if a malicious user manages to inject their own code into $news_rows, then eval() will run that, too.

I would simply use an associative array to store the results, where the keys would be the column names.