I am trying to impliment a jQuery autocomplete script which retrieves usernames from the database upon typing in a few letters.
jQuery Autocomplete Plugin
Currently I am receiving an array of data in this format from my database:
Code: Select all
Array
(
[0] => Array
(
[id] => 1
[user_id] => 63
[name] => Weiry
)
)Code: Select all
Array
(
[Weiry] => 63
)This is the current code i have which sort of comes close.. but not quite.
Code: Select all
foreach($items as $char){
$testArr[] = array("{$char['name']}" =>"{$char['user_id']}");
}Code: Select all
Array
(
[0] => Array
(
[Weiry] => 63
)
)Code: Select all
$testArr[] = "{$char['name']}" => "{$char['user_id']}";This is the function which returns the data as an array. Keep in mind that im not sure how much more i could change it, because i NEED the default array to be returned. (Yes the function is private, but im accessing it through a public method for security
Code: Select all
private function getChar($id=false,$name=false){
$q = "SELECT * FROM ".TBL_CHARS;
if($name){ $q .= " WHERE `name` = '{$name}'";
}elseif($id){ $q .= " WHERE `id` = '{$id}'";}
$r = $this->database->query($q);
if($this->database->numRows($r) > 0){
if(!$id && !$name){
while($row = $this->database->fetchAssoc($r)){
$charArr[] = $row;
}
return $charArr;
}
return $this->database->fetchAssoc($r);
}
return false;
}