简体   繁体   English

[PHP-MYSQL]查询报告

[英][PHP-MYSQL]Query for Reporting

I need help to deliver this to my client. 我需要帮助才能将此信息传达给我的客户。 He insisted that the format of the inventory report should be like this: 他坚持认为库存报告的格式应该是这样的:

报告

While my inventory table in mysql is like this: 虽然我在mysql中的库存表是这样的:

库存表

Basically he wants the application to group the inventory by item name and color then for the quantity column he want the application to show it in one column containing the size printed depend on how much the quantity is. 基本上他希望应用程序按项目名称和颜色对库存进行分组,然后对于数量列,他希望应用程序在包含打印尺寸的列中显示该数量,具体取决于数量。 So if the inventory table says we have 4 red nike shoes size 42 and 3 red nike shoes size 41 then it will be printed " 41 41 41 42 42 42 42" in this column. 因此,如果库存表显示我们有4个尺寸为42的红色耐克鞋和3个尺寸为41的红色耐克鞋,则在此栏中将打印出“41 41 41 42 42 42 42”。

I hope i explained it well,please see my inventory table and the report above for detail. 我希望我解释得很好,请查看我的库存表和上面的报告以获取详细信息。

I need advise on how to do this properly, can i do this using only sql query or should i combine it with php code as well? 我需要建议如何正确地做到这一点,我可以只使用SQL查询这样做,还是我应该将它与PHP代码结合使用?

Thanks for the help 谢谢您的帮助

Warm Regards 温暖的问候

I think you need to first use the query: 我想你需要先使用查询:

select Item,Color,GROUP_CONCAT(Size) as SIZE,GROUP_CONCAT(Qty) as Qty from --tablename-- group by Item,Color

Then use php while loop to get your result 然后使用php while循环来获得结果

while($num=$result){
$item=$num['Item'];
$Color=$num['Color'];
$size=explode(",",$num['SIZE']);
$size_show="";
$qty=$num['Qty'];
$qty1=explode(",",$qty);
foreach($size as $key=>$val){
$qty2=$qty1[$val];
$k=1;
while($k<=$qty2){
$size_show.="".$val." ";
$k++;
}

}

echo $size_show;
}

Please note that i have given only the idea, and have not tested the code 请注意,我只给出了这个想法,并没有测试代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM