我为我的joomla网站制作了2个搜索模块,它从组件中检索结果,并在搜索输入字段旁边显示为自动完成。
第一个模块从类别名称中检索结果,第二个模块从列表名称中检索结果。
这是我用于类别的PHP代码:
<?php
header('Content-Type: application/json');
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..' ));
require_once ( JPATH_BASE .DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'defines.php' );
require_once ( JPATH_BASE .DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'framework.php' );
$mainframe =& JFactory::getApplication('site',array('session'=>false));
$q = strtolower($_GET["term"]);
if (!$q) return;
$db =& JFactory::getDBO();
$query = 'SELECT cat_name FROM #__tt_cats WHERE cat_published = 1 AND cat_name LIKE ' . $db->quote('%'.$q.'%');
$db->setQuery($query);
$result = $db->loadObjectList();
$items = array();
foreach ($result AS $row) {
$items[] = $row->cat_name;
}
$json = json_encode($items);
print_r($json);
这是列表名称的php代码:
<?php
header('Content-Type: application/json');
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..' ));
require_once ( JPATH_BASE .DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'defines.php' );
require_once ( JPATH_BASE .DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'framework.php' );
$mainframe =& JFactory::getApplication('site',array('session'=>false));
$q = strtolower($_GET["term"]);
if (!$q) return;
$db =& JFactory::getDBO();
$query = 'SELECT link_name FROM #__tt_links WHERE link_name LIKE ' . $db- >quote('%'.$q.'%');
$db->setQuery($query);
$result = $db->loadObjectList();
$items = array();
foreach ($result AS $row) {
$items[] = $row->link_name;
}
$json = json_encode($items);
print_r($json);
如何合并这些文件,这样我只能使用一个搜索模块用于类别和列表名称,因此当用户执行搜索时,它会同时出现自动完成下拉菜单中的类别和列表名称的结果?
由于