4

I wanted to get the sql query like SELECT numbers FROM table ORDER BY numbers+0; in zend framework.

I am new to zend. Can anyone please help me on this.

Thank you.

1
  • sure .. you are welcome. And welcome to SO. Commented Mar 27, 2011 at 13:16

1 Answer 1

5

What about this:

    $db = Zend_Db_Table::getDefaultAdapter();
    $select = $db->select()->from('table','numbers')->order(new Zend_Db_Expr('numbers+0'));
    var_dump($select->assemble());

    //outputs: 
    //string 'SELECT `table`.`numbers` FROM `table` ORDER BY numbers+0' (length=56)

new Zend_Db_Expr is needed because without it, ZF will add 'ASC' to your query:

    $db = Zend_Db_Table::getDefaultAdapter();
    $select = $db->select()->from('table','numbers')->order('numbers+0');
    var_dump($select->assemble());

    //outputs:
    //string 'SELECT `table`.`numbers` FROM `table` ORDER BY `numbers+0` ASC' (length=62)

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

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.