Zend how do I create a left join
You could do as follows:
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select();
$select->from('advertisercontest', '*')
->joinLeft(
'advertiseraccount',
'advertiseraccount.loginid = advertisercontest.loginid',
array('advertiseraccount.advertiserid', 'advertiseraccount.companyname')
)
->where('advertisercontest.golive is not NULL');;
$result = $db->fetchAll($select);
var_dump($result);
Here is the Zend_Db_Select documentation.
Related videos on Youtube
coder3
My name is Luis D. Fernandez. I tend to be a tireless seeker of knowledge. I think this is why I enjoy software development and analyzing business opportunities. Both disciplines require extensive knowledge, both can be abstract in nature and both can be done in more than one way. My philosophy is pretty straightforward in that where you are today, is a factor in effort that you contributed to get to that place. The more [or less] you want to thrive the more [or less] effort you need to put. I believe it's practically a law in life. Baccalaureate – Psychology – 2000 | Associates - Computer Science - 2007 I am a graduate of the University of California, Los Angeles (UCLA). A resilient work ethic with a sprinkle of academic background - I should hope it reflects in my work.
Updated on June 04, 2022Comments
-
coder3 over 1 year
How do I turn this left join query:
select advertisercontest.*, advertiseraccount.advertiserid, advertiseraccount.companyname from advertisercontest left join advertiseraccount on advertiseraccount.loginid = advertisercontest.loginid where advertisercontest.golive is not NULL;
into a left join in Zend?
-
coder3 over 12 yearsAwesome!! Thanks! I have a question. I'm extending Zend_Db_Table_Abstract and I had this: $rows = $this->select()->from('advertisercontest', '*') ->joinLeft('advertiseraccount', 'advertiseraccount.loginid = advertisercontest.loginid', array('advertiseraccount.advertiserid', 'advertiseraccount.companyname')) ->where('advertisercontest.golive is not NULL') ->order('advertisercontestid DESC'); But it did not work? But your example did.. I have in my applications.ini resources.db.isDefaultTableAdapter = true
-
Marcin over 12 years@coder3. You cod probably does not work because you need to perform $rows = $this->fetchAll($select). In your case you have $rows which will be just an instance of Zend_Db_Select, not the actual results. Anyway, if you find my answer acceptable, I would be happy if you could accept it. Thanks and hope it will work.