I'm trying to create an auto complete username field using the 'Autocomplete Widgets for CCK Text and Number' module.

I've created a new 'Autocomplete for existing field data' field and have added the following code into the defaults > PHP box. (minus the php tags)

$sql = 'SELECT uid,name FROM {users} WHERE name LIKE '%s%%' ORDER BY name ASC';
$result = db_query($sql, arg(2));
$users  = db_result($result);
return array(array('value' => $users ));

I get the following error.

The default value PHP code returned an incorrect value.
Expected format:

return array(
  0 => array('value' => value for value),
  // You'll usually want to stop here. Provide more values
  // if you want your 'default value' to be multi-valued:
  1 => array('value' => value for value),
  2 => ...
);

Returned value: 

Thanks for any help.
What am I doing wrong?

Comments

SystemicPlural’s picture

$sql = "SELECT uid,name FROM {users} WHERE name LIKE '%s%%' ORDER BY name ASC";
$result = db_query($sql, arg(2));
$users  = db_result($result);
return array(array('value' => $users ));

Still looking for an answer though.

Not even sure I should be putting this code in the php defaults text box.

I'm Simply trying to create an auto complete username textbox.

ionmedia’s picture

how can i rewrite example from cck allowed values
$sql = "SELECT nid, title FROM node WHERE uid = ".$user->uid." AND type = 'customers'";
$result = db_query($sql);
while($row = db_fetch_array($res)){
$rows[$row['nid']] = $row['title'];
}
return $rows;

for using with autocomplete ?