HTML でピボット テーブルを表示するように PHP コードを変更する方法について、助けを求めています。現在、各行に場所、コンポーネント、およびカウントを含むテーブルを作成しますが、場所を列ヘッダーとして、コンポーネントを行ヘッダーとして、カウントがデータになるようにしたいと思います。
これが私のコードです:
function print_table_commodity_location_count_inbd_pivot(){
$query_items = "SELECT `tbl_origin_dest`.`name` AS 'Location',
`tbl_component`.`component_name` AS 'Component',
COUNT(`tbl_entry_item`.`entry_item_id`) AS 'Comp_Count'
FROM tbl_entry
LEFT JOIN tbl_entry_item ON `tbl_entry`.`entry_id`=`tbl_entry_item`.`entry_id`
LEFT JOIN tbl_customer ON `tbl_entry`.`customer_id`=`tbl_customer`.`customer_id`
LEFT JOIN tbl_serv_prov ON `tbl_entry`.`serv_prov_id`=`tbl_serv_prov`.`serv_prov_id`
LEFT JOIN tbl_origin_dest ON `tbl_entry`.`location`=`tbl_origin_dest`.`id`
LEFT JOIN tbl_project ON `tbl_entry`.`project_id`=`tbl_project`.`project_id`
LEFT JOIN tbl_component ON `tbl_entry_item`.`component_id`=`tbl_component`.`component_id`
WHERE `tbl_entry`.`in_out_type`='I' AND `outbound_entry_id` IS NULL AND `outbound_entry_item_id` IS NULL
GROUP BY `tbl_origin_dest`.`name`,
`tbl_component`.`component_name`";
$result_items=mysql_query($query_items);
$num_items=mysql_numrows($result_items);
echo "<table style=\"background-color: silver;\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">
<tbody>
<tr>
<td><font face=\"Arial, Helvetica, sans-serif\">Location</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\">Component</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\">Inventory Count</font></td>
</tr>";
$x=0;
while ($x < $num_items) {
$x1=mysql_result($result_items,$x,"Location");
$x2=mysql_result($result_items,$x,"Component");
$x3=mysql_result($result_items,$x,"Comp_Count");
echo "<tr>
<td><font face=\"Arial, Helvetica, sans-serif\">".$x1."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\">".$x2."</font></td>
<td><font face=\"Arial, Helvetica, sans-serif\">".$x3."</font></td>
</tr>";
$x++;
}
echo "</table>";
}
現在の結果には、各行の場所 - コンポーネント - カウントが表示されます。