Hi, I would like to loop the data-attribute to contain all column names and values from a mysql table.

This is what it looks like today:

while ($row = $result->fetch()) {
echo "<div id='{$row['namn']}' data-column1='{$row['column1']}' data-column2='{$row['column2']}'...

So some kind of magic :) loop inside there so I don't have to write all the column names manually.

Is this possible?



$i = 1;
$str = '';

foreach ($row as $column => $value)
    str .= " data-column{$i}='{$value}'";


echo $str;