Üyelik Tarihi: 19.07.2000
Yer: İstanbul
Yaş: 25
Mesaj: 153
|
php kodunda yardım
Merhaba,
urban5.com üzerinde bir online kullanıcı listesi yaratmakta sıkıntı yaşıyoruz. yüzdük yüzdük kuyruğuna geldik ancak PHP/ MySQL bilgimiz dolayısı ile burdan zoque üzerinden yardım edebilecekler çıkabilir diye düşündük.
şöyle belirteyim. hali hazırda en son işlem yapan 10 kişiyi gösteren bir kutucuğumuz mevcut ve onlie kullanıcıları çeken kod şu şekilde.
if (user_access('access content')) {
// Count users with activity in the past defined period.
$time_period = variable_get('user_block_seconds_online', 2700);
// Perform database queries to gather online user lists.
$guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$users = db_query('SELECT DISTINCT(uid), MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC', time() - $time_period );
$total_users = db_num_rows($users);
// Format the output with proper grammar.
if ($total_users == 1 && $guests->count == 1) {
$output = t('There is currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}
else {
$output = t('There are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}
// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($max_users) {
$items = array();
while ($max_users-- && $uid = db_fetch_object($users)) {
$items[] = format_name(user_load(array('uid' => $uid->uid)));
}
if ($items) {
if (db_fetch_object($users)) {
$items[] = '...';
}
$output .= theme('item_list', $items);
}
}
Bu kodtan yararlanarak aşağıda yazdığım kod üzerinde değişiklik yapmamız gerekmekte:
function profile_browse_online() {
$name = arg(1);
$value = arg(2);
$field = db_fetch_object(db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_fields} WHERE name = '%s'", $name));
if ($name && $field->fid) {
// Do not allow browsing of private fields by non-admins
if (!user_access('administer users') && $field->visibility == PROFILE_PRIVATE) {
drupal_access_denied();
return;
}
// Compile a list of fields to show
$fields = array();
$result = db_query('SELECT name, title, type FROM {profile_fields} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
$fields[] = $record;
}
// Determine what query to use:
switch ($field->type) {
case 'checkbox':
$query = 'v.value = 1';
break;
case 'selection':
$query = "v.value = '". db_escape_string($value) ."'";
break;
case 'list':
$query = "v.value LIKE '%%". db_escape_string($value) ."%%'";
break;
default:
drupal_not_found();
return;
}
// Extract the affected users:
$result = pager_query("SELECT u.uid FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query ORDER BY u.changed DESC", 20, 0, NULL, $field->fid);
$output = '<div id="profile">';
while ($account = db_fetch_object($result)) {
$output .= theme('profile_profile', user_load(array('uid' => $account->uid)), $fields);
}
$output .= theme('pager', NULL, 20);
if ($field->type == 'selection' || $field->type == 'list') {
$title = strtr($field->page, array('%value' => theme('placeholder', $value)));
}
else {
$title = $field->page;
}
$output .= '</div>';
drupal_set_title($title);
print theme('page', $output);
}
else if ($name && !$field->id) {
drupal_not_found();
}
else {
// Compile a list of fields to show
$fields = array();
$result = db_query('SELECT name, title, type FROM {profile_fields} WHERE visibility = %d', PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
$fields[] = $record;
}
// Extract the affected users:
$result = pager_query("SELECT uid FROM {users} WHERE uid > 0 ORDER BY changed DESC", 20, 0, NULL);
$output = '<div id="profile">';
while ($account = db_fetch_object($result)) {
$output .= theme('profile_profile', user_load(array('uid' => $account->uid)), $fields);
}
$output .= '</div>';
$output .= theme('pager', NULL, 20);
drupal_set_title(t('user list'));
print theme('page', $output);
}
}
aslınad uyaranması gereken ilk kodtaki database sorgusunu ikinci kodtaki sorgulara uyarlamak. umarım ayrdım edebilen biri çıkar. sevgiler...
__________________
Hisseli Harikalar Fabrikası - Atilla Baybara
HHF
|