Location: PHPKode > scripts > Impleo Music Collection Script > impleo/ajax/ac.php
<?php
/* ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <hide@address.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Christoffer Kjeldgaard Petersen
 * ----------------------------------------------------------------------------
 */

require_once('../classes/Database.class.php');
$db = Database::getInstance();
$tableStart = Database::getTableStart();

$s = strtolower($db->escapeString($_REQUEST['s']));
$t = $db->escapeString($_REQUEST['t']);

if ($t == "artist" || $t == "title" || $t == "year")
	$sql = "SELECT {$t} FROM {$tableStart}music_item WHERE {$t} LIKE '{$s}%' GROUP BY {$t} ORDER BY {$t} LIMIT 10";
else
	$sql = "SELECT v.value AS {$t} FROM {$tableStart}info_value v INNER JOIN {$tableStart}detail_types a ON a.name = v.detail WHERE v.value LIKE '{$s}%' AND a.key = '{$t}' GROUP BY v.detail ORDER BY v.detail LIMIT 10";

$arrRS = $db->fetch($sql);

$matches = array();
if ($arrRS)
{
	foreach($arrRS as $item)
	{
		$matches[] = $item[$t];
	}
}

ob_clean();
	
$type = "application/xml";
$dom = new DOMDocument('1.0');
$root = $dom->createElement('Suggestions');
for($i = 0; $i < count($matches); $i++)
{
	$e = $dom->createElement('suggestion', $matches[$i]);
	$root->appendChild($e);
}
$dom->appendChild($root);
$response = $dom->saveXML();

	header("Content-Type: $type");
	echo $response;
	exit;
?>
Return current item: Impleo Music Collection Script