2016-04-07 2 views
-2

どのようにマージするのですか?教義2つのコードの間で選択します

$collection = $this->em->getRepository('User')->createQueryBuilder('u'); 
$collection = $collection->where('u.user IN (:followers)'); 

$collection->addSelect(
    '(3959 * acos(cos(radians(' . 47.2146561 . '))' . 
    '* cos(radians(p.latitude))' . 
    '* cos(radians(p.longitude)' . 
    '- radians(' . 38.920443 . '))' . 
    '+ sin(radians(' . 47.2146561 . '))' . 
    '* sin(radians(p.latitude)))) as distance')->where('p.user = :user'); 

答えて

0

私はそれはあなたが何をしたいのですが、私の推測あなたはポジションテーブルに参加するなどの選択を追加したいされては、以下のわからない:

$collection = $this->em->getRepository('User')->createQueryBuilder('u'); 
$collection->join('u.position', 'p') 
      ->where('u.user IN (:followers)') 
      ->addSelect(
     '(3959 * acos(cos(radians('.47.2146561.')) * cos(radians(p.latitude)) * cos(radians(p.longitude) - radians('.38.920443.')) + sin(radians('.47.2146561.')) * sin(radians(p.latitude)))) as distance' 
    ) 

こちらがお役に立てば幸いです。

しかし、あなたのコードでは理解できないことがまだあります。ハードコーディングされた値で連結を使用するのはなぜですか? 代わりに変数を使用するのが目的ならば、正しい選択をしました。

+0

、もう少し情報を返信用Thxををあなたが(position表のように)聞いて次の時間を提供してください。 テスト用のハードコードされた値: 正常に動作しますが、多次元配列を返します。オブジェクトの配列が必要です –

+0

oh!私は解決策を見つけた! 距離を非表示距離に変更します。 Thx !! –

関連する問題