0

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?

Cheers!
/Adam

2
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by adishardis
2

Try:

$i = 1;
$str = '';

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

    $i++;
}

echo $str;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.