Loading ...
Sorry, an error occurred while loading the content.

Re: [phpXperts] codeigniter and mysql inner join creating problem

Expand Messages
  • asma tuli
    yeah raju vai I also tried like below $this- db- select( tbl_customer.*,tbl_sales.* ); but i did not get desired result. ... yeah raju vai I also tried  like
    Message 1 of 11 , Jul 23, 2011
    • 0 Attachment
      yeah raju vai

      I also tried  like below

      $this->db->select('tbl_customer.*,tbl_sales.*');


      but i did not get desired result.

      On Sun, Jul 24, 2011 at 6:44 AM, Zakir Hossain <rajuru@...> wrote:
       

      Hi,

      Did you selected ($this->db->select()) the columns from the second table? 


      Best Regard,
      Raju
      ------------------------
      http://hungrycoder.xenexbd.com - For novice.




      On Sat, Jul 23, 2011 at 10:14 PM, asma tuli <asmatuli@...> wrote:
       

      My problem is in this line

       

      $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');

       

      If I write the code like above line it shows nothing in view even no error is coming.

      On the other hand if I write code like the below line I got only the values of first table not the second table .

       

      $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id', ‘left’);

       

      What I have to do if same column name is in two table??

       

      I am not so expert in join with codeigniter. That’s why I am little bit confused, how to show data in view. So if you have any good tutorial regarding mysql join with codeigniter , you can share it with me.



      On Sat, Jul 23, 2011 at 9:43 PM, Md.Shoriful Islam Ronju <smronju@...> wrote:
       

      Try this...

      $sql = $this->db->select('*')
                        ->from('tbl_customer')


                        ->join('tbl_sales','tbl_sales.customer_id = tbl_customer.customer_id')
                        ->get();

      return $sql->result();



      On Sat, Jul 23, 2011 at 2:25 PM, asma tuli <asmatuli@...> wrote:
       

      my model


      function get_customer()
          {
             
              $this->db->select('*');
              $this->db->from('tbl_customer');
              $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
              $query = $this->db->get();
              return $query->result();
          }

      my controller


      function index()
          {
            $this->load->model('sh_model');
            $variable['customer'] = $this->sh_model->get_customer();
            $this->load->view('sh_view', $variable); 
          }


      my view


      foreach($customer as $item)
                      {
                              echo $item->customer_id;
                              echo $item->customer_first_name;
                      }



      I am getting no result.




      --
      :: Md.Shoriful Islam Ronju ::
      http://blog.smronju.com




    • md tipu
      Hello.. You can produce mysql query in Codeignater. Like $query=$this- db- query( SELECT * FROM TABLE ); $result=$query- row(); Simple  Thanks & Regards, 
      Message 2 of 11 , Jul 24, 2011
      • 0 Attachment
        Hello..
        You can produce mysql query in Codeignater. Like

        $query=$this->db->query("SELECT * FROM TABLE");
        $result=$query->row();

        Simple
         
        Thanks & Regards, 

        Mofizur Rahman Tipu,
        Web Application Engineer,
        Datacenter Bangladesh,
        Cell: +8801744620814, Mail: mofizur@...


        From: Zakir Hossain <rajuru@...>
        To: phpexperts@yahoogroups.com
        Sent: Sunday, July 24, 2011 6:44 AM
        Subject: Re: [phpXperts] codeigniter and mysql inner join creating problem

         

        Hi,

        Did you selected ($this->db->select()) the columns from the second table? 


        Best Regard,
        Raju
        ------------------------
        http://hungrycoder.xenexbd.com - For novice.



        On Sat, Jul 23, 2011 at 10:14 PM, asma tuli <asmatuli@...> wrote:
         

        My problem is in this line

         

        $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');

         

        If I write the code like above line it shows nothing in view even no error is coming.

        On the other hand if I write code like the below line I got only the values of first table not the second table .

         

        $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id', ‘left’);

         

        What I have to do if same column name is in two table??

         

        I am not so expert in join with codeigniter. That’s why I am little bit confused, how to show data in view. So if you have any good tutorial regarding mysql join with codeigniter , you can share it with me.



        On Sat, Jul 23, 2011 at 9:43 PM, Md.Shoriful Islam Ronju <smronju@...> wrote:
         

        Try this...

        $sql = $this->db->select('*')
                          ->from('tbl_customer')


                          ->join('tbl_sales','tbl_sales.customer_id = tbl_customer.customer_id')
                          ->get();

        return $sql->result();



        On Sat, Jul 23, 2011 at 2:25 PM, asma tuli <asmatuli@...> wrote:
         

        my model


        function get_customer()
            {
               
                $this->db->select('*');
                $this->db->from('tbl_customer');
                $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
                $query = $this->db->get();
                return $query->result();
            }

        my controller


        function index()
            {
              $this->load->model('sh_model');
              $variable['customer'] = $this->sh_model->get_customer();
              $this->load->view('sh_view', $variable); 
            }


        my view


        foreach($customer as $item)
                        {
                                echo $item->customer_id;
                                echo $item->customer_first_name;
                        }



        I am getting no result.




        --
        :: Md.Shoriful Islam Ronju ::
        http://blog.smronju.com





      • Arif Mahmud Rana
        I suggest you to first implement with sql than try to implement it in codeigniter. ARIF MAHMUD RANA ________________________________ From: asma tuli
        Message 3 of 11 , Jul 24, 2011
        • 0 Attachment
          I suggest you to first implement with sql than try to implement it in codeigniter.

          ARIF MAHMUD RANA


          From: asma tuli <asmatuli@...>
          To: phpexperts <phpexperts@yahoogroups.com>
          Sent: Saturday, July 23, 2011 2:25 PM
          Subject: [phpXperts] codeigniter and mysql inner join creating problem

           
          my model


          function get_customer()
              {
                 
                  $this->db->select('*');
                  $this->db->from('tbl_customer');
                  $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
                  $query = $this->db->get();
                  return $query->result();
              }

          my controller


          function index()
              {
                $this->load->model('sh_model');
                $variable['customer'] = $this->sh_model->get_customer();
                $this->load->view('sh_view', $variable); 
              }


          my view


          foreach($customer as $item)
                          {
                                  echo $item->customer_id;
                                  echo $item->customer_first_name;
                          }



          I am getting no result.


        • mahafuzur rahman
          try this $this- db- join( tbl_sales , tbl_sales.customer_id = tbl_customer.customer_id , left ); // for left join    $query =  $this- db- select( * )   
          Message 4 of 11 , Jul 24, 2011
          • 0 Attachment
            try this
            $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id','left');

            // for left join
               $query =  $this->db->select('*')
                                                 ->from('tbl_customer')
                                                 ->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id'
            ,'left')
                                               ->get();
            if ($query->num_rows() > 0) {
             return $query->result();
                    }
            Best Regards
            Mahfuz



            From: asma tuli <asmatuli@...>
            To: phpexperts <phpexperts@yahoogroups.com>
            Sent: Saturday, July 23, 2011 2:25 PM
            Subject: [phpXperts] codeigniter and mysql inner join creating problem

             
            my model


            function get_customer()
                {
                   
                    $this->db->select('*');
                    $this->db->from('tbl_customer');
                    $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
                    $query = $this->db->get();
                    return $query->result();
                }

            my controller


            function index()
                {
                  $this->load->model('sh_model');
                  $variable['customer'] = $this->sh_model->get_customer();
                  $this->load->view('sh_view', $variable); 
                }


            my view


            foreach($customer as $item)
                            {
                                    echo $item->customer_id;
                                    echo $item->customer_first_name;
                            }



            I am getting no result.




          • Anjan Bhowmik
            I think if you just pass the entire query to the query() function directly, its much faster and easier to debug. For my queries, i use toad for mysql freeware,
            Message 5 of 11 , Jul 24, 2011
            • 0 Attachment
              I think if you just pass the entire query to the query() function directly, its much faster and easier to debug.

              For my queries, i use toad for mysql freeware, to build and test the queries and then pass them directly to the query functions. I avoid method chaining, as thats just couple more function call and  kinda hard to debug :)

              Anyway its simply a matter of your choice how u do it.

              On Sun, Jul 24, 2011 at 4:15 PM, Arif Mahmud Rana <rarifmahmudmr9@...> wrote:
               

              I suggest you to first implement with sql than try to implement it in codeigniter.

              ARIF MAHMUD RANA


              From: asma tuli <asmatuli@...>
              To: phpexperts <phpexperts@yahoogroups.com>
              Sent: Saturday, July 23, 2011 2:25 PM
              Subject: [phpXperts] codeigniter and mysql inner join creating problem

               
              my model


              function get_customer()
                  {
                     
                      $this->db->select('*');
                      $this->db->from('tbl_customer');
                      $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
                      $query = $this->db->get();
                      return $query->result();
                  }

              my controller


              function index()
                  {
                    $this->load->model('sh_model');
                    $variable['customer'] = $this->sh_model->get_customer();
                    $this->load->view('sh_view', $variable); 
                  }


              my view


              foreach($customer as $item)
                              {
                                      echo $item->customer_id;
                                      echo $item->customer_first_name;
                              }



              I am getting no result.





              --
              Anjan Bhowmik
              Freelance Software & Web Developer
              M : +880 - 1670 - 556419
              E : anjan011@...info@...
              Site: http://www.onlyfreelancer.com/ - Only for Freelancer's!

            • asma tuli
              Thanks all who replied and tried best to help me. Actually there was a unkown database problem. I changed database and got amazing result. take care
              Message 6 of 11 , Jul 24, 2011
              • 0 Attachment
                Thanks all who replied and tried best to help me.

                Actually there was a unkown database problem. I changed database and got amazing result.

                take care

                On Sun, Jul 24, 2011 at 4:36 PM, mahafuzur rahman <mahfuz_cse05@...> wrote:
                 

                try this
                $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id','left');

                // for left join
                   $query =  $this->db->select('*')
                                                     ->from('tbl_customer')
                                                     ->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id'
                ,'left')
                                                   ->get();
                if ($query->num_rows() > 0) {
                 return $query->result();
                        }
                Best Regards
                Mahfuz



                From: asma tuli <asmatuli@...>
                To: phpexperts <phpexperts@yahoogroups.com>
                Sent: Saturday, July 23, 2011 2:25 PM
                Subject: [phpXperts] codeigniter and mysql inner join creating problem

                 
                my model


                function get_customer()
                    {
                       
                        $this->db->select('*');
                        $this->db->from('tbl_customer');
                        $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
                        $query = $this->db->get();
                        return $query->result();
                    }

                my controller


                function index()
                    {
                      $this->load->model('sh_model');
                      $variable['customer'] = $this->sh_model->get_customer();
                      $this->load->view('sh_view', $variable); 
                    }


                my view


                foreach($customer as $item)
                                {
                                        echo $item->customer_id;
                                        echo $item->customer_first_name;
                                }



                I am getting no result.





              Your message has been successfully submitted and would be delivered to recipients shortly.