[support] Default PHP Code for CCK field

Earnie Boyd earnie at users.sourceforge.net
Thu Nov 1 16:28:28 UTC 2007


Quoting Chris McCreery <chris.mccreery at gmail.com>:

> I'm sure this is an easy one for you php coders but I'm a bit confused as to
> what is currently populating my dropdown list as it is now.
>
> I have created a CCK for user reference, but I would like the default
> value(or selected value) of the dropdown list to be the current user but
> then list out the other users available, I'm not sure of the code to use for
> the PHP Code portion of the default value.
> global $user;
> return array(0 => array('value' => $user->name));
>

<?php
global $user
$result = db_query('SELECT name FROM {users} WHERE name != \'%s\'', 
$user->name);

$ret[] = $user->name

while ($u = db_fetch_object($result)) {
$ret[] = $u->name
}

return $ret;
?>

You might also want to ``ORDER BY name'' when doing the select.

Earnie -- http://for-my-kids.com/
-- http://give-me-an-offer.com/



More information about the support mailing list