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?

1
  • Where does $select come from? Commented Aug 25, 2011 at 8:13

2 Answers 2

2

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

$select->from('table_name', array('field'));
Sign up to request clarification or add additional context in comments.

Comments

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.

4 Comments

Using $this->_fetch() how do I specify a column name?
Sorry, I meant How do I specify a column name without a table name?
All the columns will be fetched.
Or in simple sentence select() is developed to work like that. Or you want to extend and make the necessary changes to work like what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.