Paginating results table

JordiTR - November 9, 2008 - 20:13
Project:User Info
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:danielskeenan
Status:active
Description

Hi you all.

I'm experimenting with that module since it's a feature lacking in drupal to be able to list all the users with some revealing profile values to study our users base. I'm not getting User Info getting to work properly, it lists weird results on my site as I commented on a previous post.

All in all, I've tried to customize it to be able to paginate the resulting table. It's obvious that this module doesn't expect more that 50 registered users, because when we have +200 the list is huge, if we got +600 the list is useless :-D

Well, I've tried to paginate the queries:

<?php
 
/**
   * Get user info
   */
  //$sql = 'SELECT * FROM `{users}` WHERE `uid` >= 1';
  //$sql_result = db_query($sql);
 
$sql_result = pager_query("SELECT * FROM `{users}` WHERE `uid` >= 1", 20, 0, NULL);
  for (
$i = 1; $i <= db_num_rows($sql_result); $i++) {
   
$result = db_fetch_array($sql_result);
   
$user_info[$result['uid']] = $result;
  }
 
/**
   * Get data for custom profile fields
   */
  //$sql = 'SELECT `name` , `uid` , `value` FROM {profile_fields} INNER JOIN {profile_values} ON {profile_fields}.fid = {profile_values}.fid';
  //$sql_result = db_query($sql);
 
$sql_result = pager_query("SELECT `name` , `uid` , `value` FROM {profile_fields} INNER JOIN {profile_values} ON {profile_fields}.fid = {profile_values}.fid", 20, 0, NULL);
  for (
$i = 1; $i <= db_num_rows($sql_result); $i++) {
   
$result = db_fetch_array($sql_result);
   
$user_info[$result['uid']][$result['name']] = $result['value'];
  }
?>

but the results are awfull, displacing results among columns. I'm able to drive myself on PHP but not enough to those two "crossed" queries. Any idea how to paginate them correctly?

#1

danielskeenan - November 9, 2008 - 21:16
Assigned to:Anonymous» danielskeenan

I've been attempting to figure out Drupal's paginator to make something like this work. This will probably show up once I fix this issue.

#2

JordiTR - November 10, 2008 - 10:01

Ok, thanks :-)

#3

manojranaweera - November 12, 2008 - 08:47

Any progress with the fix. I sure can use it right now. I desperately need to analysis our userbase, and this is the only module I believe can help me.

Many thanks Manoj

manoj@ranaweera.name
+44 7769734491
skype: ranaweeram
www.nwstartup20.co.uk

#4

danielskeenan - November 12, 2008 - 12:10

I probably won't be able to do much until at least this weekend. Asa stop gap manojranaweera, you can execute the following query to display info on custom profile fields.

SELECT `name` , `uid` , `value`
FROM PREFIX_profile_fields
INNER JOIN PREFIX_profile_values ON PREFIX_profile_fields.fid = PREFIX_profile_values.fid

Replace PREFIX with your table prefix.

Drupal should not have a problem displaying standard user fields in the"Users" Admin area.

#5

JordiTR - November 13, 2008 - 16:18

In fact, after looking at many profile snippets, I've managed to get the profile module to work with that code where I hard coded the table on the profile_browse:

<?php
 
else {
   
// Compile a list of fields to show.
   
$fields = array();
   
$result = db_query('SELECT name, title, type, weight, page FROM {profile_fields} WHERE visibility = %d ORDER BY category, weight', PROFILE_PUBLIC_LISTINGS);
    while (
$record = db_fetch_object($result)) {
     
$fields[] = $record;
    }

   
// Extract the affected users:
   
$num_users = db_num_rows(db_query('SELECT * FROM users'));
   
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 1 AND status != 0 AND access != 0 ORDER BY uid DESC', 30, 0, NULL);

   
$header = array(
           
t('UID'),
           
t('Name'),
           
t('Status'),
           
t('Field 1'),
           
t('Field 2'),
           
t('Field 3'),
           
t('Field 4'),
           
t('Field 5'),
           
t('Field 6'),
           
t('Field 7'),
           
t('Field 8')
    );
   
   
$output = '<div id="profile">';
   
$output .= '<h2 class="userlist-total">'.t('Total users: ').$num_users.'</h2>';

    while (
$account = db_fetch_object($result)) {
     
$account = user_load(array('uid' => $account->uid));
     
$profile = _profile_update_user_fields($fields, $account);
       
$rows[] = array(
       
'data' => array(
           
$account->uid,
           
$account->name,
           
$account->status,
           
$account->profile_field_1,
           
$account->profile_field_2,
           
$account->profile_field_3,
           
$account->profile_field_4,
           
$account->profile_field_5,
           
$account->profile_field_6,
           
$account->profile_field_7,
           
$account->profile_field_8
           
)
         );
    }
     
$rows[] = array(
     
'data' => array(
           array(
'data' => theme('pager', NULL, 30), 'class' => pager, 'colspan' => 11)
          )
       );

   
$output .= theme('table', $header, $rows);
   
$output .= '</div>';
   
   
drupal_set_title(t('User list'));
    return
$output;
?>

I don't know if it can be of any help, as you can see I've only touched the part realted to the presentation of the data, because I saw that the selects where already providing me the results I need. Maybe if the userinfo module was rewritten to be able to take advantage of "theme_table()" instead of trying to hardcode the table rows... Well, I don't know, it's just an idea :-)

#6

danielskeenan - November 13, 2008 - 20:09

I'll look into this. I have a show that opens next week, so life is taking over for a week or so, but after that I'll have more time.

 
 

Drupal is a registered trademark of Dries Buytaert.