سلام دوستان.
من دارم یه ماژول می نویسم واسه دروپال که اول از همه لازم دارم که لیست ایمیل همه کاربر ها رو در بیارم.
ولی نمی دونم چرا فقط اولین کاربر رو ایمیلش رو نشون میده. یعنی فقط admin رو!!
درواقع من فکر می کنم query که نوشتم مشکل داره.
کد فایل .moudule من به صورت زیر هست:
<?php
// $Id$
/**
* This module provides an email interface for administrators.
* Using this module, administrators can send email to a user from the
* user's "view" page.
* @file
*/
/**
* implementation of hook_help()
*/
function emailusers_help($path, $arg) {
if ($path == 'admin/help#emailusers') {
$txt = 'This module provides a way for an administrator to send'.
'email to a user. '.
'It assumes that the Drupal mailer is configured.';
return '<p>'. t($txt) .'</p>';
}
}
/**
* Implementation of hook_menu()
*/
function emailusers_menu() {
// Need to pass User ID here:
$items['admin/emailusers'] = array(
'title' => 'Compose a Message',
'page callback' => 'emailusers_compose',
'access arguments' => array('administer users'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Compose a message.
* This creates the form necessary to compose an email message.
*
* @param $to
* The address to send to.
* @return
* HTML.
*/
function emailusers_compose() {
$sql = "SELECT uid FROM {users} WHERE status=1";
$res = db_query($sql);
$items = db_fetch_object($res);
$count_items = count($items);
foreach($items as $item){
$userid = intval($item);
$account = user_load($userid);
$to = $account->mail;
$sb = '<p>'
.t('Send a message to @email @count', array('@email' => $to, '@count' => $count_items))
.'</p>';
}
return $sb;
}
ممنون می شم من رو راهنمائی کنید که مشکل از کجاست
تابعی که ایمیل ها را برمیگرداند بهتر است به صورت زیر انجام دهید تا نیاز به فراخوانی چندین کوئری از دیتابیس نباشد.
بقیه اجزای افزونه مربوطه مشکلی ندارند.
function emailusers_compose() {$sql = "SELECT uid,mail FROM {users} WHERE status=1";
$res = db_query($sql);
$output = '';
while($items = db_fetch_object($res)){
$output .= $items['uid'];
$output .= " -> ".$items['mail'];
$output .= "<br/>";
}
return $output;
}