I want to create form close to standard http://site/user/user

Could you tell me How I can add paging and sorting by fields (Username, Member for etc).

my version

1.
function users_list_page() {
2.

3.
$form = array();
4.
$site_users = array();
5.
$result = db_query("SELECT uid, name, status FROM {users} WHERE status = 1");
6.

7.
while ($u = db_fetch_object($result)) {
8.
array_push($site_users, $u->name);
9.
}
10.

11.
$form['site_users'] = array(
12.
'#type' => 'checkboxes',
13.
'#title' => t('Select user'),
14.
'#description' => t('Add user to role who can post without moderation.'),
15.
'#options' => ($site_users),
16.
'#value' =>($site_users)
17.
);
18.

19.
$form['submit'] = array(
20.
'#type' => 'submit',
21.
'#value' => t('Submit'),
22.
);
23.

24.
return $form;
25.
}

Comments

naveenpl’s picture

This is a sample code for drupal 5.x that i am using.

 
hook_menu (){
	$menu[] = array('path' => 'path/search',
			'title'=>t('Search Member'),
			'description' => t('Search for members.'),
			'position' => 'left',
			'weight' => 1,
			'type' => MENU_LOCAL_TASK,
			'callback' => 'search_member_overview',
			'access' => user_access('usertype'),
	);
return menu;
}

/*
 * theme for user search.
 */
function theme_search_member_form_overview($form) {
  return '<div class="container-inline">'. drupal_render($form) .'</div>';
}

/*
 * Function to display search result.
 */
function search_member_overview() {
	$output = drupal_get_form('search_member_form_overview');
	$header = array(
    array('data' => t('username'), 'field' => 'username'),
     array('data' => t('First Name'), 'field' => 'firstname'),
     array('data' => t('Operations')) 
  );
// operations if needed.
  $strclause = "";
	$valWhrCls = array();
// here insert your query
// i have give this as a string and query is executed at the end.
	$sql = 'SELECT * FROM {usertable} where 1=1 ';
	$name = $_SESSION['name_overview_filter'];
        $member = $_SESSION['member_overview_filter'];
	if(strlen($name) != NULL) {
		$strclause .= " and (username like '%s' ) ";
		$nameFilter = '%'.$name.'%';
		$valWhrCls[] = $nameFilter;
	}
	if(strlen($member) != NULL) {
		$strclause .= " and member like '%s' ";
		$nameFilter = '%'.$member.'%';
		$valWhrCls[] = $nameFilter;
	}
	// search pager query.
	$result = pager_query($sql.$strclause, 10, 0, NULL, $valWhrCls);
  while ($user = db_fetch_object($result)) {
     $rows[] = array('data' =>
      array(
                		t($user->username),
				t($user->jfirstname.' - '.$lastname),
				l(t('Contact'), 'user/'.$user->userid.'/contact'),
      )
    );
// l(t('Contact'), 'user/'.$user->userid.'/contact'), is a sample operation where 
// $user->userid is the uid in the users table.
  }
  if (!$rows) {
    $rows[] = array(array('data' => t('No records available.'), 'colspan' => 3));
  }
  $output .= theme('table', $header, $rows);
  $output .= theme('pager', NULL, 10, 0);
	return $output;
}

/*
 * display form for the user search.
 */
function search_member_form_overview() {
//#prefix and suffix are optional.
	 $form['name'] = array(
    '#type' => 'textfield',
		'#prefix' => '<table><tr><td>',
		'#suffix' => '</td></tr>',
    '#title' => t('Name'),
		'#attributes' => array('style' =>'display:block; width:190px;'),
  );
	  $form['member'] = array(
    '#type' => 'textfield',
    '#title' => t('member name'),
		'#prefix' => '<tr><td>',
		'#suffix' => '</td></tr>',
		'#attributes' => array('style' =>'display:block; width:190px;'),
  );
  $form['submit'] = array('#type' => 'submit',
    '#value' => t('Submit'),
		'#prefix' => '<tr><td>',
		'#suffix' => '</td></tr></table>',
	);
//  $form['#redirect'] = FALSE;

  return $form;
}

/*
 * Submit function for the user search.
 */
function search_member_form_overview_submit($form_id, $form_values) {
	$_SESSION['name_overview_filter'] = $form_values['name'];
	$_SESSION['member_overview_filter'] = $form_values['member'];
}
// function to validate username and member name only if needed.
function search_member_form_overview_validate($form_id, $form_values) {
}

THis is not my exact code changed for your need.
I think this will work and you need to modify the query and change it to your convenience
may be slight modification is needed.

Hope this will help
Cheers