Empire CMS provides a relatively powerful search result call. You can create most of the search functions that meet your needs according to the empire cms search form creation syntax. If you have custom fields in your database, you may need to change the data processing of e/search/index.php for form submission. You can refer to the example provided at the end of the article. Let’s take a look at the search form variable description first:
Variable name | Description | Example |
Search form submission address | POST method: /e/search/index.php | |
GET method:/e/search/?searchget=1 | /e/search/?searchget=1&keyboard=Empire&show=title | |
keyboard | Search keyword variables | |
show | Search field variable (multiple fields are separated by ",". The search field must be the field where the background model enables search) | |
classid | Search column ID (if not set to unlimited, multiple columns can be opened with ",", setting the parent column will search all sub-columns) | |
ztid | Search topic ID (if not set to unlimited, multiple topics are available "," open) | |
tbname | Search by data table (needs to be combined with search template ID) | |
tempid | Search template ID used (generally used in conjunction with table search) | |
starttime and endtime | Respectively search for information about the start time and end time of publishing (if not filled in, there is no limit. Format: 2008-02-27) | |
startprice and endprice | Respectively are the starting price and end price of the product price (if not filled in, there is no limit) | |
Search special fields | id: Search by message ID keyboard: Search by keyword (can list information by tags) userid : Search by publisher user ID username: Search by publisher username |
|
member | If the value is 0, there is no limit A value of 1 means only searching for information submitted by members If the value is 2, only the information added by the administrator will be searched |
|
orderby | Sort field: 0: By release date (default) 1: Press ID 2: By number of comments 3: Click to browse popularity 4: According to the number of downloads |
|
myorder | Sort by: 0: Sort in reverse order (default) 1: Arrange in order |
|
andor | Set the association between multi-condition queries. There are two types: or: relationship between or (default) and : the relationship of and |
|
hh | Logical operation connector variable: LT : less than GT : Greater than EQ : equal to LE : less than or equal to GE: greater than or equal to NE : Not equal to IN : Contains (search keywords separate each value with a space) BT: Range, between two values (search keywords separate two values with a space) LK: Fuzzy query (default) |
Here is an example:
<table width="320" border="0" cellspacing="1" cellpadding="3"> <form name="searchform" method="post" action="/e/search/index.php"> <tr> <td>关键字:<input name="keyboard" type="text" size="10"></td> <td>范围: <select name="show"> <option value="title">标题</option> <option value="smalltext">简介</option> <option value="newstext">内容</option> <option value="writer">作者</option> <option value="title,smalltext,newstext,writer">搜索全部</option> </select></td> </tr> <tr> <td>栏 目: <select name="classid"> <option value="0">搜索全部</option> <option value="1">新闻中心</option> <option value="4">技术文档</option> <option value="22">下载中心</option> </select> </td> <td><input type="submit" name="submit" value="搜索"></td> </tr> </form> </table>
1. Multi-field parallel search: There are two transmission methods: "string" and "array"
String passing as example:
<input type="hidden" name="hh" value="LK"> <input type="hidden" name="show" value="title,writer"> <input type="hidden" name="keyboard" value="标题,作者">
Note: The above is a fuzzy query for information that the title field contains the "title" character or the writer field contains "author"
Array passing as example:
<input type="hidden" name="hh" value="LK"> <input type="hidden" name="show[]" value="title"> <input type="hidden" name="keyboard[]" value="标题"> <input type="hidden" name="show[]" value="writer"> <input type="hidden" name="keyboard[]" value="作者">
The above is a fuzzy query for information that the title field contains the "title" character or the writer field contains "author"
2. Parallel search of multiple logical operation connectors
String passing as example:
<input type="hidden" name="hh" value="LK,EQ"> <input type="hidden" name="show" value="title,writer"> <input type="hidden" name="keyboard" value="标题,作者">
Explanation: The above is a fuzzy query for information that the title field contains the "title" character or the writer field is equal to "author"
String passing as example:
<input type="hidden" name="show[]" value="title"> <input type="hidden" name="hh[]" value="LK"> <input type="hidden" name="keyboard[]" value="标题"> <input type="hidden" name="show[]" value="writer"> <input type="hidden" name="hh[]" value="EQ"> <input type="hidden" name="keyboard[]" value="作者">
Explanation: The above is a fuzzy query for information that the title field contains the "title" character or the writer field is equal to "author".
The form design is as follows:
<form action="[!--news.url--]e/search/index.php" method="post" name="searchform" id="searchform"> <select name="classid" id="" style="display:none"> <option value="59,60,78,79,80,81" selected>全部</option> </select> <input type="hidden" name="show" value="title,myarea,mycategory,smalltext" /> <input type="hidden" name="tempid" value="1" /> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr class="even"> <td style=" text-align:left;">地区: <select name="area" id=""> <option value="">不限</option> <option value="香洲">香洲</option> <option value="吉大">吉大</option> <option value="拱北">拱北</option> <option value="新香洲">新香洲</option> <option value="前山">前山</option> <option value="南屏">南屏</option> <option value="金湾">金湾</option> <option value="斗门">斗门</option> </select> 房型: <select name="category" id=""> <option value="">不限</option> <option value="58_0">一房</option> <option value="58_1">二房</option> <option value="58_2">三房以上</option> <option value="58_3">公寓</option> <option value="58_4">写字楼</option> <option value="58_5">商铺</option> <option value="58_6">厂房</option> </select> </td> <td> </td> </tr> <tr class="even"> <td style=" text-align:left;">时间范围: <input name="starttime" type="text" value="2008-08-08" size="12" onclick="calendar.show(this);" /> 到 <input type="text" id="todayButton" name="todayButton" value="" size="12" onclick="calendar.show(this);" /> (不选则不限时段)</td> <td> </td> </tr> <tr class="even"> <td style=" text-align:left;"><input name="keyboard" type="text" size="32" value="" id="keyboard" class="inputText" /> <input type="submit" name="Submit22" value=" 搜 索 " /></td> <td></td> </tr> </tbody> </table> </form>
In order to add the search for the custom fields myarea and mycategory, we need to rewrite e/search/index.php appropriately:
$keyboard=$_POST['keyboard'].','.$_POST['area'].','.$_POST['category']; // 这是原来的:$keyboard=$_POST['keyboard']; $keyboardone=0; if(is_array($keyboard)) {} elseif(strstr($keyboard,',')) { $keyboard=explode(',',$keyboard); } else { $keyboard=trim($keyboard); $len=strlen($keyboard); if($len<$public_r[min_keyboard]||$len>$public_r[max_keyboard]) { printerror("MinKeyboard",$getfrom,1); } $keyboardone=1; }
OK, done.