I've successfully connected PostgreSQL database using PHP. And I can run queries in it.

Now that I wanted to populate week wise data.

I have some challenge in making the table header dynamic according to the number of weeks passed.

For the current month we are on week 2. So I've got two elements in an array namely `Week 1` and `Week 2`.

But the table header are defined manually to max `Week 5` which I wanted to make it dynamic to the number of weeks passed i.e., 2.

Here are the code.

```
$week_num = ceil(date('d') / 7);

for ( $i = 1; $i < $week_num + 1; $i++ ) {
        $week_table_header[] = 'Week '. $i;
    }

```

Which gives me this result.

```
Array ( [0] => Week 1 [1] => Week 2 )

```

I have this table header created using php.

```
echo "<table>
        <thead>
            <tr>
                <th></th>
                <th>Week 1</th>
                <th>Week 2</th>
                <th>Week 3</th>
                <th>Week 4</th>
                <th>Week 5</th>
            </tr>
        </thead>";

```

Where I need to get only `Week 1` and `Week 2` in the table. 

I tried using forEach.

```
   foreach ($week_table_header as $table_header) {
        # code...
        $str =  "<th>". $table_header ."</th>";

    }

```

And concatenated with the echo of the table. I got only `Week 2` which the last element in the array.

And the entire table is populated with this query.

```
while ( $row_week = pg_fetch_assoc($week_query)) {
    echo "<tr>";
    echo "<td></td>";
    echo "<td>" . $row_week['Week 1'] . "</td>";
    echo "<td>" . $row_week['Week 2'] . "</td>";
    // echo "<td>" . $row_week['Week 3'] . "</td>";
    // echo "<td>" . $row_week['Week 4'] . "</td>";
    // echo "<td>" . $row_week['Week 5'] . "</td>";
    echo "</tr>";
}

echo "</table>";

```

Even here I need to make the column names to be dynamic.

Some one help me out how can i achieve this?

Thanks in advance.