如何循环遍历 PDO 对象并将行与匹配的列分组

发布于 2025-01-18 20:17:27 字数 592 浏览 0 评论 0原文

我正在研究网络报告,需要使它看起来像以下格式。数据来自我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是伱的 2025-01-25 20:17:27

确保查询按产品线订购,然后创建一个可存储当前产品线的变量。之后,启动一个用于打印每个产品的循环,但首先检查产品的产品线是否与您存储在变量中的产品线不同。如果是这样,请打印一个新的标头,然后将此新产品线存储在变量中。

$current_product_line = "";

foreach ($products as $product) {
    if ($current_product_line!= $product["product_line"]) {
        // print header
        $current_product_line = $product["product_line"];
    }
    // print your product
}

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.

$current_product_line = "";

foreach ($products as $product) {
    if ($current_product_line!= $product["product_line"]) {
        // print header
        $current_product_line = $product["product_line"];
    }
    // print your product
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文