0

I need to build this query :

SELECT p.*, c.nazwa, c.url 
FROM posty p 
INNER JOIN posty_kategorie pc
ON pc.id_posta = p.id 
INNER JOIN kategorie c 
ON c.id = pc.id_kategorii
WHERE p.url = "przykladowy-tytul-strony"

Using CodeIgniter's Query Builder class.

All I have for now is:

return $this->db->from('posty')
                ->join('posty_kategorie', 'posty_kategorie.id_posta = posty.id', 'inner')
                ->join('kategorie', 'kategorie.id = posty_kategorie.id_kategorii')
                ->where('posty.url', $url)
                ->get()->row();

But it this doesn't work like I want it to. It has to make this query:

SELECT p.*, c.nazwa, c.url 
FROM posty p 
INNER JOIN posty_kategorie pc
ON pc.id_posta = p.id 
INNER JOIN kategorie c 
ON c.id = pc.id_kategorii
WHERE p.url = "przykladowy-tytul-strony"

But I do not know how to put this all together : < .

2
  • Have you tried: ->result_array(); insted of ->get()->row(); ? Commented May 30, 2017 at 15:20
  • Query isn't finished yet. I have no Idea how to put all this things, this whole query, into CI_Query-Builder's query syntax Commented May 30, 2017 at 15:24

1 Answer 1

1

You can try this :

$this->db->select('p.*,c.nazwa,c.url');
$this->db->from('posty p');
$this->db->join('posty_kategorie pc ', 'pc.id_posta = p.id','inner');
$this->db->join('kategorie c ', 'c.id_posta = pc.id_kategorii','inner');
$this->db->where('p.url','przykladowy-tytul-strony');
$query = $this->db->get();
return $query->result();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.