Agri Piccola
Agri Piccola

Reputation: 11

PHP - Filling in automatic table from previous database entry

I am trying to create automatic table which is filled from DB. In DB I have columns: color1, clor2 … color30. Number of colors which wanna insert depends on the calculation. Result of calculation is $j. I display table like this:

for ($i=0; $i < $j; $i++) { 
    echo "<tr class='text-center'><td class='col-sm-2 info'>";
        . "<td>" .  $row['color']
...
    . "</tr>"
    . "</td></td>”;
}

$row['color'] should depend on $i. It is not possible write $row['color$i']. How to achieve it?

Upvotes: 1

Views: 56

Answers (1)

lewnelson
lewnelson

Reputation: 69

You could either prepare your string before using it in your $row array like this $color='color'.$i then use $row[$color] or use this directly. $row["color".$i] or $row["color{$i}"] should work as well

Upvotes: 1

Related Questions