drupal sql conditional clauses for multiple tables?

前端 未结 2 638
萌比男神i
萌比男神i 2021-01-26 01:47

I have the below query for FAQ search module modified that works in Drupal 7, which searches in two tables: 1) title 2) body but don\'t manage to include one more.



        
2条回答
  •  野的像风
    2021-01-26 02:22

    $or = db_or()
      ->condition('fd.field_detailed_question_value', '%'.db_like($term ).'%', 'LIKE')
      ->condition('fb.body_value','%'.db_like($term ).'%' , 'LIKE');
    
    $results = db_select('node', 'n')
      ->fields('n', array('nid', 'title'))
      ->leftJoin('field_data_body' , 'fb', 'fb.entity_id=n.nid')
      ->leftJoin('field_data_field_detailed_question' ,'fd', 'fd.entity_id=n.nid')
      ->condition($or)
      ->execute()
      ->fetchAll();
    
    var_dump($results);
    

    db_select documentation

    db_or documentation

提交回复
热议问题