1

How to write this sql statement

SELECT * FROM `astrology` where ((commu_time_from  >= '10:30' and commu_time_from <= '10:40') or (commu_time_to  >= '10:30' and commu_time_to <= '10:40'))

in zend framework ?

2

3 Answers 3

1

I think, this works:

 $model=new Default_Model_Astronomy();
 $select=$model->getMapper()->getDbTable()->getAdapter()->select();
 $select=$select->from('astrology')
                ->where("commu_time_from  >= '10:30' and commu_time_from <= '10:40'")
                ->orWhere("commu_time_to  >= '10:30' and commu_time_to <= '10:40'");
Sign up to request clarification or add additional context in comments.

Comments

1

so:

        $db = Zend_Db::factory('Pdo_Mysql', array(
                                             'host' => '127.0.0.1',
                                             'username' => 'webuser',
                                             'password' => 'xxxxxxxx',
                                             'dbname' => 'test'
                                        ));

    $select = $db->select()
            ->from("...specify table and columns ... ")
            ->where(" ...specify search criteria ... ")
            ->order(" ...specify sorting criteria ... ");

in your specific case:

        $select = $db->select()
            ->from("astrology")
            ->where("commu_time_from  >= '10:30' AND commu_time_from <= '10:40'")
            ->orWhere("commu_time_to  >= '10:30' AND commu_time_to <= '10:40'");

1 Comment

I think the OP is struggling with the exact parameters to the from and where methods.
0

Using the select object from an instance of a Zend_Db_Table ($table in my case), Try this:

$table->select()->where('(commu_time_from >= "10:30"')
                ->where('commu_time_from <= "10:40")')
                ->orWhere('(commu_time_to >= "10:30")')
                ->where('commu_time_to <= "10:40")')

Note that the $table variable is the instance of Zend_Db_Table with the $_name property set to "astrology"

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.