Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    Php Group by problem.

    Web Development
    php web development
    4
    13
    953
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nubelle
      Nubelle Web Development last edited by

      I have a database table and I want to retrieve table data by grouping two columns , I checked this but I was not able to find a solution ? Is there any method to do this. I want to do this from php side , not mysql

      36043e19-3b5c-41c8-940f-eaa59bbfb19b-image.png

      1 Reply Last reply Reply Quote 1
      • root
        root Linux Help last edited by root

        Not clear about your columns ? which columns you wants to group ??

        Nubelle 1 Reply Last reply Reply Quote 0
        • Nubelle
          Nubelle Web Development @root last edited by Nubelle

          @root root I want to group data by year and tyepe, I tried to do it using mysql. but failed.

          dev_lak 1 Reply Last reply Reply Quote 0
          • root
            root Linux Help last edited by

            Okay i'll try to find a solution .

            1 Reply Last reply Reply Quote 0
            • dev_lak
              dev_lak @Nubelle last edited by

              @Nubelle did you get any error?

              Nubelle 1 Reply Last reply Reply Quote 0
              • KrissSachintha
                KrissSachintha last edited by

                Did group by year,type throwed an error?

                Nubelle 1 Reply Last reply Reply Quote 0
                • root
                  root Linux Help last edited by root

                  $array = [];
                  
                  //$table_data is mysql returned array, you can change this whatever you want
                  foreach($table_data as $row) {
                      $key = $row['type'] . '-' . $row['year'];
                      if (!isset($array[$key])) {
                          $array[$key] = $row;
                      }
                  }
                  
                  

                  Try with this , i think this is correct solution for your issue.

                  Nubelle 2 Replies Last reply Reply Quote 0
                  • Nubelle
                    Nubelle Web Development @dev_lak last edited by

                    @dev_lak No when I add groupBy function mysql said to disable some features , when I disable them other functions not working

                    1 Reply Last reply Reply Quote 0
                    • Nubelle
                      Nubelle Web Development @KrissSachintha last edited by

                      @KrissSachintha No when I add groupBy function mysql said to disable some features , when I disable them other functions not working

                      1 Reply Last reply Reply Quote 0
                      • Nubelle
                        Nubelle Web Development @root last edited by

                        @root Thanks , let me try this

                        1 Reply Last reply Reply Quote 0
                        • Nubelle
                          Nubelle Web Development @root last edited by

                          @root hi root this is working , Thanks 269f1ebd-04d9-4dbd-a514-ba4a789aebb4-image.png

                          root 1 Reply Last reply Reply Quote 1
                          • root
                            root Linux Help @Nubelle last edited by

                            @Nubelle

                            Ohh great bro, i'm very happy to help you.

                            1 Reply Last reply Reply Quote 0
                            • Nubelle
                              Nubelle Web Development last edited by

                              Thanks all

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post

                              0
                              Online

                              3.6k
                              Users

                              1.3k
                              Topics

                              5.3k
                              Posts

                              • Privacy
                              • Terms & Conditions
                              • Donate

                              © Copyrights and All right reserved Lanka Developers Community

                              Powered by Axis Technologies (PVT) Ltd

                              Made with in Sri Lanka

                              | |