I have this table:
`product_id` int(11) NOT NULL,
`source_id` int(11) NOT NULL,
`initial_price` float(7,2) NOT NULL,
`sale_price` float(7,2) NOT NULL
And my output is like this:
<table border="1" class="table">
<thead>
<tr class="border-0">
<th class="border-0">Product name</th>
<th class="border-0">Source ID 1</th>
<th class="border-0">Source ID 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Product 1 name</td>
<td>old_price<br>sale_price of source_id 1</td>
<td>old_price<br>sale_price of source_id 2</td>
</tr>
<tr>
<td>Product 2 name</td>
<td>old_price<br>sale_price of source_id 1</td>
<td>old_price<br>sale_price of source_id 2</td>
</tr>
<tr>
<td>Product 3 name</td>
<td>old_price<br>sale_price of source_id 1</td>
<td>old_price<br>sale_price of source_id 2</td>
</tr>
</tbody>
</table>
I want to display like this:
<table border="1" class="table">
<thead>
<tr class="border-0">
<th class="border-0">Product name</th>
<th class="border-0">Source ID 1</th>
<th class="border-0">Source ID 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Product 1 name</td>
<td>old_price<br>sale_price of source_id 1</td>
<td>old_price<br>sale_price of source_id 1</td>
</tr>
<tr>
<td>Product 2 name</td>
<td>old_price<br>sale_price of source_id 2</td>
<td>old_price<br>sale_price of source_id 2</td>
</tr>
<tr>
<td>Product 3 name</td>
<td>old_price<br>sale_price of source_id 3</td>
<td>old_price<br>sale_price of source_id 3</td>
</tr>
</tbody>
</table>
So, all rows from Source ID1 must be columns for Product name 1 all rows from Source ID2 must be columns for Product name 2
Currently I use this SELECT:
$products = $db->prepare("SELECT source_id, product_id,
initial_price, sale_price
from products");
How need to be my select to output like example from table 2 from snippet?