Community

php in page to create user profile list

I found this code for drupal 5 and wondering if there is a way to use it for drupal 7 instead of using views to create list of profiles?

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

while (
$record = db_fetch_object($result)) {
     
$fields[] = $record;
}

// v.fid = 1 is the include in member gallery checkbox
// If the field contains integer values use ORDER BY ABS(v.value) to force numeric sorting

//Change the 50 to display more or less users per page
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = 1 ORDER BY u.name, v.value ASC", 50, 0, NULL);

$output = '<div id="profile">';
while (
$account = db_fetch_object($result)) {
$account = user_load(array('uid' => $account->uid));
$profile = _profile_update_user_fields($fields, $account);
$output .= theme('profile_listing', $account, $profile);
}
$output .= '</div>';
$output .= theme('pager', NULL, 20);

return
$output;
?>

Comments

=-=

To use it for drupal7 it would have to be rewritten as users in D7 are entities.

views.module is a viable alternative to custom code for a list of users these days

php

interesting how many ppl out there bypass with php. I did end up using views, you could do an entire course on views so its always kind of daunting.

=-=

why write php and mysql when there is no need to?

use views, export the view into a custom module. you get the php and mysql. done

agreed

But I guess if you were proficient in writing php you might use it instead of modules in certain cases.
I am not so I won't .

=-=

in certain cases. It's also worthy to note that some things which required php prior to D7 no longer do because drupal's internals have changed.

also of note, when you export a view for use in a custom module, you don't have to write any php or mysql. I place all my views in custom modules so that I can lessen the burden on the database.

interesting