The following code works well for displaying a paginated list of Drupal users.
function generate_list() {
$query = db_select('users', 'u')
->extend('PagerDefault')
->fields('u', array('name', 'uid'))
->orderBy('created', 'DESC')
->limit(20);
$result = $query->execute();
$list = array();
foreach ($result as $row) {
$list[] = sprintf('<a href="/user.php?id=DE%u">%s</a>', $row->uid, $row->name);
}
$theme_args = array('items' => $list, 'type' => 'ul');
return theme('item_list', $theme_args) . theme('pager');
}
I tried fetching from an external SQL-table using the following code.
function generate_list() {
$query = db_select('pref_users', 'u')
->extend('PagerDefault')
->fields('u', array('first_name', 'id'))
->orderBy('created', 'DESC')
->limit(20);
$result = $query->execute();
$list = array();
foreach ($result as $row) {
$list[] = sprintf('<a href="/user.php?id=%s">%s</a>', $row->id, $row->first_name);
}
$theme_args = array('items' => $list, 'type' => 'ul');
return theme('item_list', $theme_args) . theme('pager');
}
I get this error.
PDOException: SQLSTATE[42P01]: Undefined table: 7
ERROR: relation "drupal_pref_users" does not exist at character 67: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {pref_users} u) subquery; Array() in method PagerDefault->execute() (line 75 in file includes/pager.inc).
Does anybody please know a way to tell Drupal to fetch data from pref_users and not from {pref_users} at it seems to do?