Not sure how to word this question well but hopefully someone can help... I'm trying to select data from a MySQL database and output it to a HTML table using PHP whereby data from the query forms the column headings and rows. The data in my 'budget' table looks like:
I want to output the Customer in the rows, Week in the columns and sum of the Qty as the data. So far, I have:
<? $q1 = mysqli_query($conn, "SELECT customer, week, sum(qty) AS qty FROM budget GROUP BY week, customer"); ?>
<table>
<thead>
<tr>
<th>Customer</th>
<th>Week</th>
<th>Qty</th>
</tr>
</thead>
<tbody>
<? while($row1 = mysqli_fetch_assoc($q1)){ ?>
<tr>
<td><?= $row1['customer']; ?></td>
<td><?= $row1['week']; ?></td>
<td><?= $row1['qty']; ?></td>
</tr>
<? } ?>
</tbody>
</table>
This produces a table similar to the original MySQL table format but what i'm trying to achieve is:
The week selection will be dynamic so it could be 4 or 36 weeks that i'd want in the columns depending on their selection in a form.

