Sure, though, as you’ll see, this snippet is authored against a custom xPDO data model (xPDOAdmin extends xPDO and encapsulates the connection to the database), and might have some PHP 5 only syntax, though that could be easily remedied.
<?php
$output= '';
$team_contact= '';
if (isset ($_GET['search'])) {
$team_contact= $_GET['search'];
}
if ($team_contact) {
include_once ($modx->config['base_path'] . 'assets/snippets/admin/xpdoadmin.class.php');
$xpdo= & new xPDOAdmin($modx);
$results= array ();
$criteria= new xPDOCriteria($xpdo, "SELECT * FROM {$xpdo->getTableName('TeamContacts')} WHERE `name` LIKE {$xpdo->quote($team_contact . '%')} ORDER BY `name` ASC LIMIT 0,20");
if ($collection= $xpdo->getCollection('TeamContacts', $criteria)) {
foreach ($collection as $itemKey => $item) {
$results[]= array (
"id" => $itemKey,
"value" => $item->get('name'),
"info" => implode(', ', $item->get(array('city','state')))
);
}
} else {
return '';
}
foreach ($results as $result) {
$jsonResults[]= $xpdo->toJSON($result);
}
$modx->setPlaceholder('autosuggest-results', implode(",", $jsonResults));
}
$output.= $modx->getChunk('autosuggest.json.outer');
return $output;
And here is the chunk autosuggest.json.outer for reference...
{ results: [
[+autosuggest-results+]
] }