how to use joins in Zend_Paginator_Adapter_DbSelect()

317 views Asked by At

how can i replace below mysql query to ZF Zend_Paginator_Adapter_DbSelect() query

$sql = "SELECT ps.phone_service_id,ps.phone_service_name,ps.phone_service_Duration,ps.phone_service_type,us.user_preferences_value,ps.user_id FROM phone_service ps,user_preferences us
    WHERE us.phone_service_id = ps.phone_service_id
    AND us.user_preferences_name = 'is_user_package_active'
   AND ps.user_id =".$user_id;

i write this one but error occur could you please replace my query to equailent Zend_Paginator_Adapter_DbSelect()

$select = $DB->select()
              ->from(array('ps' => 'phone_service'
                           'us' => 'user_preferences'),
                array('ps.phone_service_id', 'ps.phone_service_name','ps.phone_service_Duration','ps.phone_service_type','us.user_preferences_value')),
                ->where('us.phone_service_id = ?', 'ps.phone_service_id')
                ->where( 'us.user_preferences_name = ?', 'is_user_package_active')
                ->where( 'us.user_id = ?', $user_id)
                ;
1

There are 1 answers

3
dbrumann On BEST ANSWER

I guess you want something like this:

$sel = $db->select();
$sel->from(array('p' => 'phone_service'))
    ->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
    ->where('u.user_preferences_name = ?', 'is_user_package_active')
    ->where('p.user_id = ?', $user_id);