Codeigniter Inner join query not working

11,068

I think you need to remove "->db" from last line.
So your query will be

$query = $this->db->select('StockMain.*, StockDetail.*')
              ->from('StockMain')
              ->join('StockDetail', 'StockMain.vrnoa = StockDetail.vrnoa', 'inner')
              ->where('StockMain.vrnoa', $vrnoa);
              ->get();
Share:
11,068
Kamran Ahmed
Author by

Kamran Ahmed

@kamranahmedse github.com/kamranahmedse roadmap.sh

Updated on June 13, 2022

Comments

  • Kamran Ahmed
    Kamran Ahmed almost 2 years

    I've written the following Inner joing query that works perfectly.

    $query = $this->db->query('SELECT * FROM StockMain INNER JOIN StockDetail ON StockMain.vrnoa = StockDetail.vrnoa WHERE StockMain.vrnoa = ' . $vrnoa);
    

    Then I thought to transform it to the following:

    $query = $this->db->select('StockMain.*, StockDetail.*')
                  ->from('StockMain')
                  ->join('StockDetail', 'StockMain.vrnoa = StockDetail.vrnoa', 'inner')
                  ->where('StockMain.vrnoa', $vrnoa);
                  ->db->get();
    

    But due to some strange reason it isn't working. Can anyone please tell me what I am doing wrong here. Why does this second query not work as both are the same?