Quantcast

Problem with JOIN

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with JOIN

Carlos Castro-2
Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with JOIN

Carlos Castro-2

Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with JOIN

Carlos Castro-2

Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with JOIN

Carlos Castro-2
In reply to this post by Carlos Castro-2
Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with JOIN

Carlos Castro-2
In reply to this post by Carlos Castro-2
Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with JOIN

Hector Virgen
Hi Carlos,

The third parameter to join() accepts an array of columns to return for that table.

Since you are passing in an empty array, it is performing the join but not selecting any of the values. Try this and it should work:

->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID'array('Descricao'))

-Hector


On Wed, Nov 26, 2008 at 9:44 AM, Carlos Castro <[hidden email]> wrote:
Hi,
I want to obtain a field from table 'dirempresasbragaempresas'. So:


$empresa = new Empresa();
$this->view->rows = $empresa->fetchAll($empresa->select()->setIntegrityCheck(false)
->join(array('sae' => 'sectoractividade_empresa'), 'sae.EmpresaNIPC=empresa.NIPC', array())
->join(array('sa' => 'sectoractividade'), 'sa.CAE=sae.SectorActividadeCAE', array())
->join(array('debe' => 'dirempresasbragaempresas'), 'debe.ID=sa.DirEmpresasBragaEmpresasID', array())
->where('empresa.Estado = ?', 'A')
->order('rand()')->limit(5, 0));


When i do:
foreach ($this->rows as $Row){
{$Row->Nome}
}
I can get the value from the field 'Nome' that came from table 'empresa'.

When i do:
foreach ($this->rows as $Row){
{$Row->Descricao}
} That is a field from table 'dirempresasbragaempresas', i have the next error:
Fatal error: Uncaught exception 'Zend_Db_Table_Row_Exception' with message 'Specified column "Descricao" is not in the row' in /Applications/MAMP/htdocs/BragaDigital/library/Zend/Db/Table/Row/Abstract.php:182

Thanks by helping me!!



--
Hector Virgen
Loading...