Zend Framework: How to combine three tables in one query using Joins?

The reference guide is the best starting point to learn about Zend_Db_Select Along with my example below, of course: $db is an instance of Zend_Db_Adapter_Abstract $select = $db->select(); $select->from(array('p' => 'person'), array('person_id', 'name', 'dob')) ->join(array('pa' => 'Person_Address'), 'pa. Person_id = p. Person_id', array()) ->join(array('a' => 'Address'), 'a.

Address_id = pa. Address_id', array('address_id', 'street', 'city', 'state', 'country')) It's then as simple as this to fetch a row: $db->fetchRow($select) In debugging Zend_Db_Select there's a clever trick you can use - simply print the select object, which in turn invokes the toString method to produce SQl: echo $select; //prints SQL.

The reference guide is the best starting point to learn about Zend_Db_Select. Along with my example below, of course: //$db is an instance of Zend_Db_Adapter_Abstract $select = $db->select(); $select->from(array('p' => 'person'), array('person_id', 'name', 'dob')) ->join(array('pa' => 'Person_Address'), 'pa. Person_id = p.

Person_id', array()) ->join(array('a' => 'Address'), 'a. Address_id = pa. Address_id', array('address_id', 'street', 'city', 'state', 'country')); It's then as simple as this to fetch a row: $db->fetchRow($select); In debugging Zend_Db_Select there's a clever trick you can use - simply print the select object, which in turn invokes the toString method to produce SQl: echo $select; //prints SQL.

I'm not sure if you're looking for SQL to do the above, or code using Zend's facilities. Given the presence of "sql" and "joins" in the tags, here's the SQL you'd need: SELECT p. Person_id, p.Name, p.

Dob, a. Address_id, street, city, state, country FROM person p INNER JOIN Person_Address pa ON pa. Person_id = p.

Person_id INNER JOIN Address a ON a. Address_id = pa. Address_id Bear in mind that the Person_Address tells us that there's a many-to-many relationship between a Person and an Address.

Many Persons may share an Address, and a Person may have more than one address. The SQL above will show ALL such relationships.So if Naveed has two Address records, you will have two rows in the result set with person_id = 1.

Yes, I am looking for JOINs support in zend and want to know that how to implement your above query in zend. In my scenario one person has only one address at a time. Anyway thanks for your response and your query will help me.

– NAVEED Mar 1 '10 at 11:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions