如何循环遍历 PDO 对象并将行与匹配的列分组
我正在研究网络报告,需要使它看起来像以下格式。数据来自我在PHP中获得的PDO对象。但是我不确定如何打印出来,以免重复product_line,因为PDO项目中的每个条目都有产品线。它应该打印产品线,然后在转到下一个产品线之前使用该产品线打印所有作业。是否可以循环遍历我的PDO对象,打印出product_line,然后在转到下一个product_line之前打印每个具有匹配product_line的项目?
Part Job Seq Workcenter Source Cause Date Notes
---------------------------------------------------------
Product_Line
103V A306 003 Bending Prep Wrong 4/1/2022 blah blah blah
102V B306 002 Laser Op Laser error 3/31/2022 some more notes
Product_Line
864A M037 008 Waterjet skids detail wrong 3/31/2022 more notes
I am working on a web report and I need to have it look like the below format. The data is coming from a PDO object that I get in php. but I am not sure how I can print this out so that the product_line isn't repeated because each entry in the PDO project does have a product line. It should print the product line and then print all jobs with that product line before moving on to the next product line. is it possible to loop through my PDO object, print out a product_line, then print every item with matching product_line before moving on to the next product_line?
Part Job Seq Workcenter Source Cause Date Notes
---------------------------------------------------------
Product_Line
103V A306 003 Bending Prep Wrong 4/1/2022 blah blah blah
102V B306 002 Laser Op Laser error 3/31/2022 some more notes
Product_Line
864A M037 008 Waterjet skids detail wrong 3/31/2022 more notes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保查询按产品线订购,然后创建一个可存储当前产品线的变量。之后,启动一个用于打印每个产品的循环,但首先检查产品的产品线是否与您存储在变量中的产品线不同。如果是这样,请打印一个新的标头,然后将此新产品线存储在变量中。
make sure your query is ordering by product line, then create a variable to store the current product line. after, start a for loop to print each product, but first check if the product line of the product is different from the one you stored in the variable. if so, print a new header and, store this new product line in the variable.