0

I have trouble with pulling data from two different tables. I'm attempting to first grab all the addresses with a given name (select all the addresses with the name tom in table). Then with the addresses, look through another table (table2) for those addresses and pull a all the data from col number. Is there a better way than my code:

CONTROLLER:

this->table = new Address();  
$getaddress = $this->table->getAddress($name); //grabbing all address associated with a given name

$address = $getaddress->toArray();

foreach ($addy as $address)
{
   this->table2 = new Number();
   $numbers = $this->table2->getNumber($address['numberColumn']);
   $this->view->numbers = $numbers->toArray();
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
michael liu
  • 55
  • 1
  • 7

1 Answers1

0

I will advice you to define relationship between table and table2. Of course you need foreign key in table2 which will be the relation to the first table. Please study this document: http://framework.zend.com/manual/1.12/en/zend.db.table.relationships.html

konradwww
  • 693
  • 7
  • 16
  • I omitted that part to get to the main point of my question. Table and Table 2 are different tables with the common field address. I'm trying to input a name, retrieve the addresses from table, and then look up all the addresses and retrieve the numbers from Table2 that contains all the addresses. So basically iterate through address1, address2, address3 etc and fetchAll(//fetch numbers WHERE address1 OR address2 OR address3 etc) – michael liu Feb 27 '13 at 14:06
  • Could you provide db diagram or sql create statment for those 2 tables? Maybe there a need to change the table structure or relations... – konradwww Feb 28 '13 at 07:49