|
|
|
form search and page มีปัญหาเรือง กด next page และค้นหา ไม่ตรงกัน รบถวนถามหน่อยคับ |
|
|
|
|
|
|
|
ผมทำฟังก์ชั่น ค้นหา แต่มีปัญหา ตามรูปคับแก้ไขอย่างไรคับ
Code (PHP)
function epaper_search_page_form($form,&$form_state){ // search database
$module_path = drupal_get_path('module', 'epaper');
drupal_add_css($module_path . '/css/epaper_form.css');
$form = array();
$options_t = array(0 =>' - Select - ');
$result = db_select('tb_type', 't')->fields('t')->execute();
while ($row = $result->fetchAssoc()){
$options_t[$row['id']] = $row['type'];
}
$options_c = array(0 =>' - Select - ');
$result = db_select('tb_category', 'c')->fields('c')->execute();
while ($row = $result->fetchAssoc()){
$options_c[$row['id']] = $row['cate'];
}
$optionsm = array(0 => 'Select',
'01' => 'Jan',
'02' => 'Feb',
'03' => 'Mar',
'04' => 'Apr',
'05' => 'May',
'06' => 'Jun',
'07' => 'Jul',
'08' => 'Aug',
'09' => 'Sep',
'10' => 'Oct',
'11' => 'Nov',
'12' => 'Dec',
);
$form['type'] = array(
'#type' => 'select',
'#title' => 'Type',
'#options' => $options_t,
);
$form['cate'] = array(
'#type' => 'select',
'#title' => 'Category',
'#options' => $options_c,
);
$y_current = date('Y')+543;
$parenty = array_combine(range($y_current, 2500),range($y_current, 2500));
$optionsy = array(0 => t('Select'));
$optionsy += $parenty;
$form['yea1'] = array(
'#type' => 'select',
'#title' => 'Year',
'#options' => $optionsy,
'#suffix' => '<div class="clear"></div>',
);
$form['subj'] = array(
'#type' => 'textfield',
'#title' => 'Keyword',
'#size' => 40,
'#default_value' => '',
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
$search_type = isset($form_state['values']['type']) ? $form_state['values']['type'] : 0;
$search_cate = isset($form_state['values']['cate']) ? $form_state['values']['cate'] : 0;
$search_yea1 = isset($form_state['values']['yea1']) ? $form_state['values']['yea1'] : 0;
$search_string = isset($form_state['values']['subj']) ? $form_state['values']['subj'] : '';
$header = array(
'id' => array('data' => t('ID', array(), array('context' => 'id')), 'field' => 'p.id'),
'type' => array('data' => t('Type', array(), array('context' => 'type')), 'field' => 'p.type'),
'category' => array('data' => t('Category', array(), array('context' => 'Category')), 'field' => 'p.cate'),
'signingdate' => array('data' => t('SigningDate', array(), array('context' => 'SigningDate'))),
'departmentno' => array('data' => t('DepartmentNo', array(), array('context' => 'DepartmentNo')), 'field' => 'p.bookat'),
'subject' => array('data' => t('Subject', array(), array('context' => 'Subject')), 'field' => 'p.subj'));
$query = db_select('tb_paper', 'p');
$query->leftJoin('tb_type','t','p.type = t.id');
$query->leftJoin('tb_category','c','p.cate = c.id');
if ($search_type > 0) {
$query->condition('p.id', $id);
$header['category']['sort'] = 'asc';
}
if($search_type > 0) {
$query->condition('p.type', $search_type, 'LIKE');
}
if($search_cate > 0) {
$query->condition('p.cate', $search_cate, 'LIKE');
}
if($search_yea1 > 0) {
$query->condition('p.yea1', $search_yea1, 'LIKE');
}
if(strlen($search_string) > 0) {
$query->condition('p.subj', '%' . $search_string . '%', 'LIKE');
}
$count_query = clone $query;
$count_query->addExpression('COUNT(p.id)');
$found = $count_query->execute()->fetchField();
//print_r($found);
$query = $query->extend('PagerDefault')->extend('TableSort');
$query->limit(3)->orderByHeader($header) ;
$query->setCountQuery($count_query);
$query->fields('p', array('id', 'type', 'cate', 'date1', 'mon1', 'yea1', 'bookat', 'subj', 'rem', 'file'));
$result = $query->execute();
$options = array();
foreach ($result as $record) {
$options[$record->id] = array(
'id' => $record->id,
'type' => $options_t[$record->type],
'category' => $options_c[$record->cate],
'signingdate' => $record->date1 . ' ' . $optionsm[$record->mon1]. ' ' . $record->yea1,
'departmentno' => $record->bookat,
$fid = $record->file,
$file = file_load($fid),
$uri = $file->uri,
$url = file_create_url($uri),
'subject' => l($record->subj, $url,array('attributes'=>array('target'=>'_blank'))),
);
}
$def = isset($found) ? $found : '0';
$def = $def .' '. 'rows';
$form['found'] = array(
'#type' => 'item',
'#title' => t('Total : '),
'#markup' => $def,
);
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No item available.'),
);
//print_r($found);
$form['pager'] = array('#markup' => theme('pager'));
$form['#theme'] = 'status_summary_theme';
return $form;
}
Tag : PHP
|
|
|
|
|
|
Date :
2015-09-11 09:24:29 |
By :
varin_srichan |
View :
760 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดู URL ที่เป็น Next Page มันส่งค่าอะไรไปบ้างครับ
|
|
|
|
|
Date :
2015-09-11 10:42:17 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่งค่านี่้คับ ?page=1
|
ประวัติการแก้ไข 2015-09-11 10:52:47
|
|
|
|
Date :
2015-09-11 10:51:12 |
By :
varin_srichan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|