CodeIgniter Forums
join problem - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: join problem (/thread-9985.html)

join problem - El Forum - 07-15-2008

excuse me for my english.

I use Activerecord in my model
$this->db->join('clienti_authors_related', 'clienti_authors_related.author_id = authors.author_id AND clienti_authors_related.cliente_id = 1');

Result: 0 records.

I try the query result (last_query()) in phpmyadmin:
FROM authors
JOIN clienti_authors_related ON clienti_authors_related.author_id = authors.author_id AND clienti_authors_related.cliente_id = 1

Result: 2 records.


Is this a bug?


join problem - El Forum - 03-06-2012

I think i have the some problem...

$this->db->join('catalogs_arranges', 'catalogs_arranges.key=nexts AND', 'LEFT');

create this:
LEFT JOIN `catalogs_arranges` ON `catalogs_arranges`.`key`=`nexts` AND

The "nexts" string is "protected" by CI... What is the solution??

join problem - El Forum - 03-06-2012

add 'left' as a third parameter to your join in active record and see if you get the same results.

I don't expect you will since both CI and mysql default to Inner join.

You also don't want to forget

$this->db->from('table_name') only specifies the table it doesn't actually run the query.

join problem - El Forum - 03-06-2012

Thanks Matalina, i think you do not understand my question Tongue

I replace the JOIN by sub SELECT:
$this->db->select('(SELECT arrange FROM catalogs_arranges WHERE catalogs_arranges.key="nexts" AND AS arrange');

It works, but i think JOIN may be is better.

join problem - El Forum - 03-06-2012

My reply was in reference to the original poster.

join problem - El Forum - 03-06-2012

[quote author="Matalina" date="1331073441"]My reply was in reference to the original poster.[/quote]

Uops... sorry!

join problem - El Forum - 03-07-2012

Josepzin, in your case, it's not about CI protect the "nexts" string, but because it IS a string. You'll need to put it in a string anyway.

Also, try switching the condition of joining. I cannot remember why but I did got some problem like that before, somehow, I realized that I have to put the "relation" part ( before the "condition" part (catalogs_arranges.key="nexts").....

Although "join" could be replaced with "where", the usage are not the same :3.

join problem - El Forum - 03-07-2012

Thnaks aquary!!!! Smile

It works, your two options are good!

$this->db->where('catalogs_arranges.key', 'nexts');
$this->db->join('catalogs_arranges', '', 'LEFT');

$this->db->join('catalogs_arranges', ' AND catalogs_arranges.key="nexts"', 'LEFT');