P
P
Pavel2015-12-17 11:48:20
Drupal
Pavel, 2015-12-17 11:48:20

Multiple Autocomplete search for form text field?

Guys, I'm dumb. Tell me, in general, there is a form with a text field, to which autocomplete is attached, the callback itself looks like this:

<?php

function searchform_autocomplete_search($string) {
  
  $matches = array();
  
  $result = db_select('field_data_field_sku', 't')
    ->fields('t', array('field_sku_value'))
    ->condition('field_sku_value', '%' . db_like($string) . '%', 'LIKE')
    ->range(0, 10)
    ->execute()
    ->fetchAll();
  
  foreach ($result as $row) {
    $matches[$row->field_sku_value] = check_plain($row->field_sku_value);
  }

  drupal_json_output($matches);
  
}

in fact, everything is simple if the search goes through one table. I need to fasten the search on 2 tables to this, the name for the example of the 2nd table is field_data_field_new_sku. Besides, what to concoct the 2nd query on the second table, nothing comes to mind. I think there is a beautiful option, how to pull values ​​from 2 tables in one query to the database?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question