0

I cant convert this below query to Zend_Db:

SELECT `mfaq`.* FROM `m_faq` AS `mfaq`
WHERE (mfaq.delete_flg <> 'D' OR mfaq.delete_flg IS NULL)
AND ((mfaq.title like '%$title%')
OR (mfaq.title like '%$title%')
AND (mfaq.title like '%$title%') 
OR (mfaq.title like '%$title%'))
ORDER BY `create_date` DESC 

Some help???

1 Answer 1

1

First you need to have created dbtable model:

class Application_Model_DbTable_Mfaq extends Zend_Db_Table_Abstract
{
    protected $_name = 'm_faq';
}

Then use it as follows:

$table = new Application_Model_DbTable_Mfaq();

$select = $table->getAdapter()->select()
            ->from(array('mfaq'=>$table->info(Zend_Db_Table::NAME)))
            ->where("( mfaq.delete_flg <> 'D'")
            ->orWhere("mfaq.delete_flg IS NULL )")
            ->where("( mfaq.title like ?", "%$title%")
            ->orWhere("mfaq.title like ? ", "%$title%")
            ->where(" mfaq.title like ?", "%$title%")
            ->orWhere("mfaq.title like ? )", "%$title%")
            ->order("create_date DESC");

// echo $select; // shows your sql
$results = $select->query()->fetchAll();

I hope, you take into account that AND have higher priority than OR.

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.