how to get data from the 3 tables according to date wise in codeiginter?












1














public function St_statement() {

$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;

if ($this->input->post('all')) {
$query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC ")->result_array();

$data['query'] = $query1;

$this->load->view('Inventory/St_Stmt', $data);

}

if ($this->input->post('selected')) {
if ($name = $this->input->post('businessType')) {
$query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE `pgroup` = '$name' AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC")->result_array();

$data['query'] = $query1;

$this->load->view('Inventory/St_Stmt', $data);

}

}
}


this is a controller code.....



my problem is how to get data from the four tables using date wise in codeiginter.
when i using where condition it only fetch the data if all the tables presents, otherwise it does not display the item.enter image description here



this picture used where condition.it shows only all three tables have same item.enter image description here



this picture does not used where condition but it shows all the data if it is not present or not.



please help to solve this problem










share|improve this question





























    1














    public function St_statement() {

    $startdate = $this->input->post('SDate');
    $enddate = $this->input->post('EDate');
    $date = str_replace('/', '-', $startdate);
    $newDate = date("Y-m-d", strtotime($date));
    $date2 = str_replace('/', '-', $enddate);
    $newDate2 = date("Y-m-d", strtotime($date2));
    $data['startdate'] = $startdate;
    $data['enddate'] = $enddate;

    if ($this->input->post('all')) {
    $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC ")->result_array();

    $data['query'] = $query1;

    $this->load->view('Inventory/St_Stmt', $data);

    }

    if ($this->input->post('selected')) {
    if ($name = $this->input->post('businessType')) {
    $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE `pgroup` = '$name' AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC")->result_array();

    $data['query'] = $query1;

    $this->load->view('Inventory/St_Stmt', $data);

    }

    }
    }


    this is a controller code.....



    my problem is how to get data from the four tables using date wise in codeiginter.
    when i using where condition it only fetch the data if all the tables presents, otherwise it does not display the item.enter image description here



    this picture used where condition.it shows only all three tables have same item.enter image description here



    this picture does not used where condition but it shows all the data if it is not present or not.



    please help to solve this problem










    share|improve this question



























      1












      1








      1







      public function St_statement() {

      $startdate = $this->input->post('SDate');
      $enddate = $this->input->post('EDate');
      $date = str_replace('/', '-', $startdate);
      $newDate = date("Y-m-d", strtotime($date));
      $date2 = str_replace('/', '-', $enddate);
      $newDate2 = date("Y-m-d", strtotime($date2));
      $data['startdate'] = $startdate;
      $data['enddate'] = $enddate;

      if ($this->input->post('all')) {
      $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC ")->result_array();

      $data['query'] = $query1;

      $this->load->view('Inventory/St_Stmt', $data);

      }

      if ($this->input->post('selected')) {
      if ($name = $this->input->post('businessType')) {
      $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE `pgroup` = '$name' AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC")->result_array();

      $data['query'] = $query1;

      $this->load->view('Inventory/St_Stmt', $data);

      }

      }
      }


      this is a controller code.....



      my problem is how to get data from the four tables using date wise in codeiginter.
      when i using where condition it only fetch the data if all the tables presents, otherwise it does not display the item.enter image description here



      this picture used where condition.it shows only all three tables have same item.enter image description here



      this picture does not used where condition but it shows all the data if it is not present or not.



      please help to solve this problem










      share|improve this question















      public function St_statement() {

      $startdate = $this->input->post('SDate');
      $enddate = $this->input->post('EDate');
      $date = str_replace('/', '-', $startdate);
      $newDate = date("Y-m-d", strtotime($date));
      $date2 = str_replace('/', '-', $enddate);
      $newDate2 = date("Y-m-d", strtotime($date2));
      $data['startdate'] = $startdate;
      $data['enddate'] = $enddate;

      if ($this->input->post('all')) {
      $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC ")->result_array();

      $data['query'] = $query1;

      $this->load->view('Inventory/St_Stmt', $data);

      }

      if ($this->input->post('selected')) {
      if ($name = $this->input->post('businessType')) {
      $query1 = $this->db->query("SELECT `pgroup`,`Item`, SUM(`Stock`) AS `Stock`,SUM(`quantity`) AS `quantity`,SUM(`Qty`) AS `Qty`FROM `opstock` LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` LEFT OUTER JOIN `itemmaster` ON `itemmaster`.`itemname` = `opstock`.`Item` LEFT OUTER JOIN `pgroup` ON `pgroup`.`pgroupid` = `itemmaster`.`catcode` LEFT OUTER JOIN `purchaseitem` ON `purchaseitem`.`Prdtname` = `opstock`.`Item` WHERE `pgroup` = '$name' AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' GROUP BY `Item` ORDER BY `pgroup` ASC")->result_array();

      $data['query'] = $query1;

      $this->load->view('Inventory/St_Stmt', $data);

      }

      }
      }


      this is a controller code.....



      my problem is how to get data from the four tables using date wise in codeiginter.
      when i using where condition it only fetch the data if all the tables presents, otherwise it does not display the item.enter image description here



      this picture used where condition.it shows only all three tables have same item.enter image description here



      this picture does not used where condition but it shows all the data if it is not present or not.



      please help to solve this problem







      php mysql codeigniter join






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 9:43









      Nesku

      318111




      318111










      asked Nov 20 '18 at 9:19









      Teddy

      5810




      5810
























          2 Answers
          2






          active

          oldest

          votes


















          2














          move that where condition statement to "ON" it will work.



          Eg.



          LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' 


          If its in where , which is common for the all above conditions. That's why you are not getting any result. So remove it from where condition and move that condition to "ON" statement.






          share|improve this answer





















          • thank you @AGK i got the correct ans
            – Teddy
            Nov 20 '18 at 10:10



















          -1














          i can't comment so no insults :3 i did not really understand your problem but you need to put the query inside the modal or else why using codeigniter, and you can make functions insie the modal for each table and make the query easier without joint etc..






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389753%2fhow-to-get-data-from-the-3-tables-according-to-date-wise-in-codeiginter%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            move that where condition statement to "ON" it will work.



            Eg.



            LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' 


            If its in where , which is common for the all above conditions. That's why you are not getting any result. So remove it from where condition and move that condition to "ON" statement.






            share|improve this answer





















            • thank you @AGK i got the correct ans
              – Teddy
              Nov 20 '18 at 10:10
















            2














            move that where condition statement to "ON" it will work.



            Eg.



            LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' 


            If its in where , which is common for the all above conditions. That's why you are not getting any result. So remove it from where condition and move that condition to "ON" statement.






            share|improve this answer





















            • thank you @AGK i got the correct ans
              – Teddy
              Nov 20 '18 at 10:10














            2












            2








            2






            move that where condition statement to "ON" it will work.



            Eg.



            LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' 


            If its in where , which is common for the all above conditions. That's why you are not getting any result. So remove it from where condition and move that condition to "ON" statement.






            share|improve this answer












            move that where condition statement to "ON" it will work.



            Eg.



            LEFT OUTER JOIN `salesitem` ON `salesitem`.`Prdtname` = `opstock`.`Item` AND billdte >= '$newDate' AND billdte <= '$newDate2' AND billdate >= '$newDate' AND billdate <= '$newDate2' 


            If its in where , which is common for the all above conditions. That's why you are not getting any result. So remove it from where condition and move that condition to "ON" statement.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 '18 at 9:45









            AGK

            5812




            5812












            • thank you @AGK i got the correct ans
              – Teddy
              Nov 20 '18 at 10:10


















            • thank you @AGK i got the correct ans
              – Teddy
              Nov 20 '18 at 10:10
















            thank you @AGK i got the correct ans
            – Teddy
            Nov 20 '18 at 10:10




            thank you @AGK i got the correct ans
            – Teddy
            Nov 20 '18 at 10:10













            -1














            i can't comment so no insults :3 i did not really understand your problem but you need to put the query inside the modal or else why using codeigniter, and you can make functions insie the modal for each table and make the query easier without joint etc..






            share|improve this answer


























              -1














              i can't comment so no insults :3 i did not really understand your problem but you need to put the query inside the modal or else why using codeigniter, and you can make functions insie the modal for each table and make the query easier without joint etc..






              share|improve this answer
























                -1












                -1








                -1






                i can't comment so no insults :3 i did not really understand your problem but you need to put the query inside the modal or else why using codeigniter, and you can make functions insie the modal for each table and make the query easier without joint etc..






                share|improve this answer












                i can't comment so no insults :3 i did not really understand your problem but you need to put the query inside the modal or else why using codeigniter, and you can make functions insie the modal for each table and make the query easier without joint etc..







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 9:41









                ChiKa LiO

                448




                448






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389753%2fhow-to-get-data-from-the-3-tables-according-to-date-wise-in-codeiginter%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?