0

I want to use select() where I can get just one column without specifying the table name. (Table name is in the $_name var declared in my model.) I tried this:

$select->columns('field');

.. but I get error of "No table has been specified for the FROM clause" - so it looks like it's expecting a table name.

Is there a way of getting just one column?

Owen
  • 7,347
  • 12
  • 54
  • 73

2 Answers2

2

The error is correct. You need to specify a table you want the field from.

$select->from('table_name', array('field'));
adlawson
  • 6,303
  • 1
  • 35
  • 46
1

If your class extends the Zend_Db_Table_Abstract, you can use $this->fetchAll() , so no table name need to be specified.

If you still want to use select() pass the $this->_name as you have already declared the value $_name .

$this->select()->from($this->_name);

select() is mainly used to create a select query object, so it cannot guess from which table you are going to though currently you are in the model. It may not be for a query on the same table. So you should pass the table name. For more see http://framework.zend.com/manual/en/zend.db.select.html . All are for different purposes. So you want to use according to your wish.

Hari K T
  • 4,174
  • 3
  • 32
  • 51