用于搜索内容的Drupal表单

时间:2013-05-24 11:29:53

标签: drupal drupal-forms drupal-form-submission

我正在尝试使用特定字段值创建搜索节点的表单。以下是我的表格。该节点包含一个城市字段,一个分类术语等。我想知道的是如何在新的drupal页面中显示我从mysql select中得到的结果

    function q_search_form($form_state) {
$form['qsearch']['category'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 2 => 'Automotive', 1 => 'Real Estate'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<table width="470"><tr><td width="170">Select Category</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['city'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 'kozhikode' => 'Kozhikode', 'kochi' => 'Kochi'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">City</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['property'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 18 => 'Land and House', 17 => 'Land'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Property</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['wanto'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 'sell' => 'Sell', 'buy' => 'Buy'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Want to</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
    '#attributes' => array('id' => 'Search', 'class' => 'srch-button'),
    '#prefix' => '<tr><td><a class="adv-srch" href="#">Advance Search</a></td><td>',
    '#suffix' => '</td></tr></table>'
);
return $form;
}

 function q_search_form_submit($form, &$form_state) {
   $wantto = $form_state['values']['wanto'];
    $property = $form_state['values']['property'];
    $city = $form_state['values']['city'];
     $category = $form_state['values']['category'];
      $sql = ' SELECT A.nid FROM node A 
        LEFT JOIN content_type_item B ON A.vid = B.vid
        LEFT JOIN term_node C ON A.vid = C.vid
        LEFT JOIN term_hierarchy D ON D.tid = C.tid
        WHERE A.type = "item" 
        AND B.field_tr_type_value = "'.$wantto.'"
        AND B.field_city_value = "'.$city.'"
        AND D.parent = '.$category.'
        AND C.tid = '.$property.'
   ';
   $result = db_query($sql);   

   }

1 个答案:

答案 0 :(得分:0)

在您的查询尝试类似这样的内容后,

while($result = db_fetch_array($sql)){
  $output .= "<div>$result['somevalue']</div>";
  $output .= " <br/> ";
}
if (isset($sql)) {
  drupal_set_message(t('Search submitted successfully.'));     
}else {   
  drupal_set_message(t('Please try again.'));      
}
return $output;